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

Comments

Projects
None yet
9 participants
@amkgo
Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link

commented Jul 15, 2017

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

@smcquay

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

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