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/http: Server.Close may not able to close all connections #48642
Comments
Change https://golang.org/cl/353714 mentions this issue: |
CC @neild |
I think this was not the correct fix. The proper fix should close accepted connection only if server is closed As I am not sure what is the correct way to revert the change I've created a #52823 |
Change https://go.dev/cl/405454 mentions this issue: |
The https://golang.org/cl/353714 wrongly closes accepted connection if server is shutting down. Updates golang#33313 Fixes golang#36819 Fixes golang#48642
The https://golang.org/cl/353714 wrongly closes accepted connection if server is shutting down. Updates golang#33313 Fixes golang#36819 Fixes golang#48642
The https://golang.org/cl/353714 wrongly closes accepted connection if server is shutting down. Updates golang#33313 Fixes golang#36819 Fixes golang#48642
The https://golang.org/cl/353714 wrongly closes accepted connection if server is shutting down. Updates golang#33313 Fixes golang#36819 Fixes golang#48642
Fix is being reverted. |
This reverts CL 353714. The change closes accepted connection also in graceful shutdown which breaks the fix for #33313 (and apparent duplicate #36819). The proper fix should close accepted connection only if server is closed but not in graceful shutdown. Updates #48642 Change-Id: I2f7005f3f3037e6563745731bb2693923b654004 GitHub-Last-Rev: f6d885a GitHub-Pull-Request: #52823 Reviewed-on: https://go-review.googlesource.com/c/go/+/405454 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
Previous attempt https://golang.org/cl/353714 also incorrectly closed accepted connection while in shutdown. Fixes golang#48642 Updates golang#33313, golang#36819
Change https://go.dev/cl/409154 mentions this issue: |
Change https://go.dev/cl/409537 mentions this issue: |
@neild What is the status of this issue? It's currently in the 1.19 milestone. Thanks. |
Avoid race conditions when a new connection is accepted just after Server.Close or Server.Shutdown is called by waiting for the listener goroutines to exit before proceeding to clean up active connections. No test because the mechanism required to trigger the race condition reliably requires such tight coupling to the Server internals that any test would be quite fragile in the face of reasonable refactorings. Fixes golang#48642 Updates golang#33313, golang#36819 Change-Id: I109a93362680991bf298e0a95637595dcaa884af Reviewed-on: https://go-review.googlesource.com/c/go/+/409537 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
I encountered lingering connection after calling Server.Close and it's not closed by Server.Close
Here is reproducible example: https://play.golang.org/p/9aLVDwWPQhH
The problem is http/server.go: Server.Serve function didn't check if Server is already closed before calling handler, and if Server.Close been called after l.Accept return but before c.setState(c.rwc, StateNew, runHooks), the new connection is not registered in the activeConn map when Server.Close try to close all connections.
The example code simulate this condition by sleep one second during ConnContext call. Program can exit corrected if this sleep is removed.
The text was updated successfully, but these errors were encountered: