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: gracefully shutdown file server #19541

Closed
amkgo opened this issue Mar 14, 2017 · 6 comments
Closed

net/http: gracefully shutdown file server #19541

amkgo opened this issue Mar 14, 2017 · 6 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@amkgo
Copy link

amkgo commented Mar 14, 2017

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

@ALTree ALTree changed the title Gracefully shutdown file server net/http: gracefully shutdown file server Mar 14, 2017
@ALTree ALTree added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 14, 2017
@mb0
Copy link

mb0 commented Mar 14, 2017

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
Copy link
Contributor

@amkgo, do you have a repro?

@mb0, that is true, but do you have any evidence that this is OP's problem?

@mb0
Copy link

mb0 commented Mar 14, 2017

@bradfitz no sorry. i tried to reproduce and my assumption was wrong.
the problem is something else and even more obvious in hindsight.

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.

@amkgo
Copy link
Author

amkgo commented Mar 14, 2017

The example code https://play.golang.org/p/LdXUYyzDxY by @mb0 works great.

I think we can close this issue. Thank you all!

@amkgo
Copy link
Author

amkgo commented Mar 15, 2017

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

@bradfitz
Copy link
Contributor

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.

@golang golang locked and limited conversation to collaborators Mar 15, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants