Skip to content
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: Shutdown() may hangs forever #53729

Closed
cryptocifer opened this issue Jul 7, 2022 · 1 comment
Closed

net/http: Shutdown() may hangs forever #53729

cryptocifer opened this issue Jul 7, 2022 · 1 comment

Comments

@cryptocifer
Copy link

cryptocifer commented Jul 7, 2022

What version of Go are you using (go version)?

$ go version
1.18.3

Does this issue reproduce with the latest release?

seldomly reproduced

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOHOSTARCH="amd64"
GOVERSION="go1.18.3"

What did you do?

We have a program that runs a net/http server and it keeps two persistent connections with a client. Our program catches users' SIGINT signal and calls net/http.Shutdown() to terminate the server.

Yesterday, I hit Ctrl-c to terminate my program hence the http server, just as uasual, but the program just stuck, hopefully I triggered a pprof and got the full goroutines snapshot, I found my program stuck at the net/http.Shutdown() function.

After reading the documentation and the source code of net/http.Shutdown(), I realized that Shutdown() waits indefinitely for connections to become idle before closing them and returning.

So I think this is just what I encountered: the two persistent connections are too busy to become idle. But I then feel it's really low probable, since according to the source code, the http server turns the connection into idle once it sends the response and Shutdown() checks the connections in a very frequent manner.

I just post it here for some inspiration and see if I am the only lucky man who encountered this issue.

btw, the in reality issue I encountered in:
ethereum/go-ethereum#25257

@cryptocifer cryptocifer changed the title affected/package: net/http affected/package: net/http Shutdown may hangs forever Jul 7, 2022
@cryptocifer cryptocifer changed the title affected/package: net/http Shutdown may hangs forever net/http: Shutdown() may hangs forever Jul 7, 2022
@seankhliao
Copy link
Member

That would be working as expected, maybe you want to set http.Server.BaseContext in your code

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jul 7, 2022
@golang golang locked and limited conversation to collaborators Jul 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants