-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
net: DialContext can use a stale context via happy eyeballs #21600
Comments
@bcmills, I'm reconsidering whether this and #21597 are actually bugs. The documentation for httptrace explicitly says that "Functions may be called concurrently from different goroutines and some may be called after the request has completed or failed." I don't see any documentation in Both this issue and #21597 arise from an internal Google package that implements a context type, where the Value method of that type panics if called after the context has gone out-of-scope (where "out-of-scope" has a well-defined meaning for that specific package). In terms of the vanilla |
Over-retaining a This is more of an issue with |
I don't think there is any such thing as a "stale context." A better way to put this might be that the current happy eyeballs code can keep a context value live unnecessarily. But I don't think this is true. The happy eyeballs code calls So I don't see a bug here. I haven't looked at the code for #21597, but from reading the issue my impression is that that code does not currently use a cancelable context to cancel pending actions. If that is correct, then the issues do not seem similar. |
That's true, and makes the over-retention here much less severe in practice than the one in #21597, but because |
Agreed, but my guess is that on balance the current behavior is preferable. It doesn't penalize the common case. |
In the common case (where we are not overloaded on CPU), it shouldn't make much difference one way or the other. If dialSingle really is responsive to cancellation, the amount of latency added by waiting for the goroutine to return should be negligible compared to the latency of dialing a network connection. That is: the difference only matters when dialSingle is not responsive, and that is precisely the condition under which the over-retention is likely to matter too. |
The common case is that a |
AFAIK there are no actual cases where someone suffered an OOM due to func Go(ctx context, f func(context)) {
c := newCtx(ctx)
go func() {
defer close(c.closed)
f(c)
}()
}
func (c ctx) Value(key interface{}) interface{} {
select{
case <-c.closed:
panic("Value called after ctx done")
default:
}
...
} The open question is whether that panic should exist. There are two ways to view the question:
/cc @zombiezen @Sajmani |
That's not at all obvious to me. Yes, an individual |
When happy eyeballs is enabled, DialContext makes parallel calls to dialSingle via dialParallel:
go/src/net/dial.go
Line 415 in 424b065
Each dialSingle call may call ctx.Value, such as here:
go/src/net/dial.go
Line 533 in 424b065
dialParallel doesn't wait for all dialSingle calls to complete. This means, in theory, dialSingle can call ctx.Value on a ctx that has gone out of scope. This is effectively the same problem as #21597.
/cc @bcmills
The text was updated successfully, but these errors were encountered: