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
Bug in listing 7.5 (graceful server shutdown) #11
Comments
Thanks @joergjo - correct catch indeed. |
This is interesting indeed. I wonder how you managed to catch it? Was it just your knowledge of how the |
As far as I remember, I ran the server and for whatever reason had it running long enough to exceed the deadline. I have tried various graceful shutdown techniques when building Go servers, so on second glance that context seemed misplaced. |
Thanks a lot for filing the issue and bringing this to my attention, fixed in master, will create a new release now. |
The sample will only work as intended if the server is shutdown within ~30 seconds after launching, because the context's deadline is set directly at server launch. Running the sample and waiting for > 30 seconds before hitting CTRL+C produces
The deadline to shutdown the server has been reached, but not because the clean shutdown took too long, but because the deadline was already exceeded when
s.Shutdown(ctx)
was called.To fix this,
context.WithTimeout()
should be called in theshutdown
function:The text was updated successfully, but these errors were encountered: