-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: gracefully shutdown file server #19541
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
the client is probably using a series of range request for large downloads. http.FileServer supports range queries and returns 206 partial content. that means after srv.Shutdown is called, it will only wait for the active range requests and close the connection when it changes into idle state. the client cannot open a new connection because the listener is already closed. |
@bradfitz no sorry. i tried to reproduce and my assumption was wrong. the playground example will return from ListenAndServe and thus exit as soon as the listening socket it closed. if the example does not exit the program right away Shutdown behavior works as expected. |
The example code https://play.golang.org/p/LdXUYyzDxY by @mb0 works great. I think we can close this issue. Thank you all! |
I think lots of gophers may encounter this problem and don't aware of it. Because I got the code from the web and the authors maybe Go experts(Speakers). Can you please add some comments to server.Shutdown() to explain how to properly use it. The main function should wait for Shutdown() to finish to make it function properly. Or at least a link to this issue. Thanks |
Sure, file a new bug that's just about documenting Server.Shutdown more. Title: "net/http: add example for Server.Shutdown" The example will not reference this issue (we don't link to bugs or commits in Go docs) but your new documentation bug can and should reference this bug. |
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 discussed here: https://groups.google.com/forum/#!topic/golang-nuts/Aca1YAX6Uxc
Andrew
The text was updated successfully, but these errors were encountered: