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

Closed
amkgo opened this issue Mar 16, 2017 · 7 comments
Closed

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

amkgo opened this issue Mar 16, 2017 · 7 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@amkgo
Copy link

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?

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

@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
@pierrre
Copy link

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

@loopthrough
Copy link

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.
https://go-review.googlesource.com/c/45094

I am looking as well into testing it properly, but wanted to check if this approach is reasonable to move forward with.

@fraenkel
Copy link
Contributor

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.

@amkgo
Copy link
Author

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.

@gopherbot
Copy link

CL https://golang.org/cl/48869 mentions this issue.

@smcquay
Copy link
Contributor

smcquay commented Jul 15, 2017

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

https://play.golang.org/p/wnUgZfHh2W

Does that not behave as expected?

@mrwonko
Copy link

mrwonko commented Jul 24, 2017

I think this is related to #20239

@bradfitz bradfitz modified the milestones: Go1.10, Go1.9 Jul 24, 2017
@bradfitz bradfitz added NeedsFix The path to resolution is known, but the work has not been done. release-blocker labels Jul 24, 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.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

9 participants