-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: connCount underflow panic with MaxConnsPerHost #38172
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
Comments
I just noticed that the binary that stack trace is from was compiled with Go 1.14, not Go 1.14.1 like I had thought originally. But we got the same panics with a binary compiled on Linux with Go 1.14.1. |
connCount underflow
panic with MaxConnsPerHost
@andybalholm, could you try testing with a |
Building with
I still get the panic:
|
@bcmills This is an http request issue not http2. |
@andybalholm, could you share some more detail about your usage? (Any unusual |
If you have a bunch of these panic traces, are there any that don't have that stack sequence (decConnsPerHost called from closeLocked called from close)? |
@bcmills Here is my transport: var dialer = &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}
var httpTransport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: dialer.DialContext,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
} The environment doesn't specify a proxy. I call |
@rsc All the stack traces seem to have that sequence. And |
One thing I realize is that we dont check the return of removeIdleConnLocked during closeConnIfStillIdle before we blindly close the persistConn. |
More interesting is that the order of pc.close() and removeIdleConn vary which means we could easily get into this situation. |
@andybalholm I am confused. You mention that you set MaxConnsPerHost = 8, but the above does not show you setting it. Where/When did you do that. |
I set MaxConnsPerHost and IdleConnTimeout after reading the config file, since those can be changed in the config.
Andy
… On Apr 8, 2020, at 5:49 PM, Michael Fraenkel ***@***.***> wrote:
@andybalholm <https://github.com/andybalholm> I am confused. You mention that you set MaxConnsPerHost = 8, but the above does not show you setting it. Where/When did you do that.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#38172 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAGUELAAFUMZ3EFYNUYHKA3RLULP3ANCNFSM4LXEF2QA>.
|
@andybalholm, do you set those after the What happens if you run your program under the race detector? |
Good point. I only set them as part of the initial startup (not on configuration reload), but it’s after some server goroutines have been started. I’ll try moving those settings to an earlier stage of initialization, and see what happens.
… On Apr 9, 2020, at 1:46 PM, Bryan C. Mills ***@***.***> wrote:
@andybalholm <https://github.com/andybalholm>, do you set those after the Transport is already in use? I don't believe that's safe in general. (It wouldn't surprise me if it's even a data race.)
What happens if you run your program under the race detector <https://golang.org/doc/articles/race_detector.html>?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#38172 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAGUELGBI6LIXLXKMA2W7MDRLYXZPANCNFSM4LXEF2QA>.
|
Can you run with -race? That would catch this pretty fast if it was done later. |
I can't run it with -race on the server where I was getting the panics; it's too heavily loaded. But I tried it on a local server with just me proxied through it, and that was enough:
It's been several years since I tried running with -race. I didn't find anything then, and I figured only a heavily-loaded production server would have enough concurrency to expose races if there were any. But now I know that running with -race locally is worth doing. Reordering the startup steps gets rid of the race. |
Running go 1.14.6 or 1.14.7 Since this is a different code path and happening during automatic cleanup, seems like this shouldn't happen... panic: net/http: internal error: connCount underflow Should I open a new issue for this? |
@mrjrieke please try your code with the race detector, as that proved to be the problem above. If that doesn't reveal a mistake, please file a new issue. |
I'm splitting this off from #34941 because it seems to be a separate issue, although with the same symptom.
I compiled this binary on macOS, but I'm running it on Linux amd64.
Here is the stack trace:
The usage is in a forward proxy server (github.com/andybalholm/redwood). We have about 2000 users running through the server I have been watching these errors on the most closely. So the usage is heavy, and probably about as close to random as you are likely to find.
I thought that switching to two Transports (one for HTTP/1.1 and one for HTTP/2) instead of one
http.Transport
that was configured to automatically switch protocols would get rid of the panics. But it didn't seem to help. (So it seems that the panic doesn't depend on having HTTP/2 enabled on the Transport.)I had
Transport.MaxConnsPerHost
set to 8. Setting it to 0 (unlimited) made the panics go away.The text was updated successfully, but these errors were encountered: