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

Comments

Projects
None yet
5 participants
@amkgo
Copy link

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

@mb0

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Member

commented Mar 14, 2017

@amkgo, do you have a repro?

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

@mb0

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Author

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!

@bradfitz bradfitz closed this Mar 14, 2017

@amkgo

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Member

commented Mar 15, 2017

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.
You can’t perform that action at this time.