-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: add examples/comments for Server.Shutdown #19579
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 agree, I was trying to implement a graceful shutdown in my app. |
I looked a bit into this one and made a small change to embed the synchronisation of Shutdown() and Serve() in the net/http itself instead of expecting to synchronise them through main. Proposal for the change. I am looking as well into testing it properly, but wanted to check if this approach is reasonable to move forward with. |
None of these prevent someone calling Serve during a Shutdown or even after Shutdown. The fix seems to handle a very specific use of Server and not the case where you have potentially multiple listeners. |
I've used Nginx before and it can be shutdown or restart gracefully. Maybe we can get some ideas from it. |
CL https://golang.org/cl/48869 mentions this issue. |
@amkgo I added a chan communication before exit and after shutdown: https://play.golang.org/p/wnUgZfHh2W Does that not behave as expected? |
I think this is related to #20239 |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Go 1.8
What operating system and processor architecture are you using (
go env
)?amd64(windows 7 & Ubuntu 16.04)
What did you do?
https://play.golang.org/p/Akv3se9kkZ
What did you expect to see?
Go file server shutdown after download the file or timeout is reached
What did you see instead?
File server shutdown immediately
This issue is related to #19541.
The Shutdown function may need some comments or examples to warn gophers to keep ListenAndServe running until it finished.
Or if possible, make Shutdown communicate with ListenAndServe internally to make https://play.golang.org/p/Akv3se9kkZ works.
Thanks,
Andrew
The text was updated successfully, but these errors were encountered: