-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pass a context to Transport.ConnContext #4536
Conversation
9047fdd
to
a7be08d
Compare
b827d6b
to
53fed79
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4536 +/- ##
==========================================
- Coverage 85.16% 85.14% -0.01%
==========================================
Files 154 154
Lines 14835 14841 +6
==========================================
+ Hits 12633 12636 +3
- Misses 1695 1698 +3
Partials 507 507 ☔ View full report in Codecov by Sentry. |
// The context returned from the callback is used to derive every other context used during the | ||
// lifetime of the connection: | ||
// * the context passed to crypto/tls (and used on the tls.ClientHelloInfo) | ||
// * the context used in Config.Tracer | ||
// * the context returned from Connection.Context | ||
// * the context returned from SendStream.Context | ||
// It is not used for dialed connections. | ||
ConnContext func() context.Context | ||
ConnContext func(context.Context) context.Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's another restriction here: The context returned MUST be derived from the context passed into ConnContext
.
We can:
- Document it.
- Document and enforce it, by attaching an internal value to the context, and checking that it exists on the returned context (and panic if not).
- Remove this requirement. This means we'll have to pass a second
context.CancelCauseFunc
to the connection struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we derive a context from the context returned from transport.ConnContext
?
I mean
ctx, cancel = context.WithCancelCause(s.connContext())
...
conn = s.newConn(ctx, cancel ...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise 3 seems the nicest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we derive a context from the context returned from
transport.ConnContext
?I mean
ctx, cancel = context.WithCancelCause(s.connContext()) ... conn = s.newConn(ctx, cancel ...)
I don't think that works, since we want the context we pass to ConnContext
to be canceled when the connection is closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we can do 3 without any major refactor. A context.ContextCancelFunc
is just a fancy name for a func(error)
, so we can just wrap the cancel func of the original and the returned context into one function.
This context is cancelled when the QUIC connection is closed, or when the QUIC handshake fails. This allows the application to easily build and garbage collect a map of active connections.
ee95767
to
4413c73
Compare
This context is cancelled when the QUIC connection is closed, or when the QUIC handshake fails. This allows the application to easily build and garbage collect a map of active connections.
TODO: