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: add examples/comments for Server.Shutdown #19579

amkgo opened this issue Mar 16, 2017 · 7 comments

net/http: add examples/comments for Server.Shutdown #19579

amkgo opened this issue Mar 16, 2017 · 7 comments


Copy link

@amkgo amkgo commented Mar 16, 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?

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 works.


@amkgo amkgo changed the title net/http: Shutdown Documentation net/http: add examples/comments for Server.Shutdown Mar 16, 2017
@bradfitz bradfitz added this to the Go1.9 milestone Mar 16, 2017
Copy link

@pierrre pierrre commented Mar 22, 2017

I agree, ListenAndServe() should block until Shutdown() returns.

I was trying to implement a graceful shutdown in my app.
I think I'll move the Shutdown() call to my "main/blocking execution path".

Copy link

@loopthrough loopthrough commented Jun 8, 2017

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.

Copy link

@fraenkel fraenkel commented Jun 9, 2017

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.

Copy link

@amkgo amkgo commented Jun 23, 2017

I've used Nginx before and it can be shutdown or restart gracefully. Maybe we can get some ideas from it.

Copy link

@gopherbot gopherbot commented Jul 15, 2017

CL mentions this issue.

Copy link

@smcquay smcquay commented Jul 15, 2017

@amkgo I added a chan communication before exit and after shutdown:

Does that not behave as expected?

Copy link

@mrwonko mrwonko commented Jul 24, 2017

I think this is related to #20239

@bradfitz bradfitz modified the milestones: Go1.10, Go1.9 Jul 24, 2017
@gopherbot gopherbot closed this in b29bb78 Nov 14, 2017
@golang golang locked and limited conversation to collaborators Nov 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
9 participants