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

Add call to wg.Wait() before returning from Serve(), fix server tests #10

Merged
merged 1 commit into from
Apr 17, 2014

Conversation

kainosnoema
Copy link
Contributor

Though the readme states clearly that "the call to server.ListenAndServe will stop blocking when all the requests are finished", this doesn't seem to be the case. I've put together multiple tests, and at least in Go 1.2, as soon as the listener is closed and Accept() starts returning an error, http.Serve returns with that error immediately. Is it possible this is new behavior in Go 1.2?

In any case, manners isn't calling wg.Wait() anywhere, so the process exits and all in-flight routines are killed. Essentially, it's currently doing nothing, as far as I can tell. The tests in server_test.go pass because the process is still running when the test completes, meaning the goroutines eventually finish even after the server has shut down, even though in most environments they would be killed.

This patch adds a call to wg.Wait() before returning from Serve() when the listener has been closed, and fixes the test to actually check whether the request has completed before the server shuts down. Tested and working well with Go 1.2.

http.Serve does not wait for requests to finish, so we have to wait
for the GracefulServer's WaitGroup to reach zero, or the process will
exit and in-flight routines will be killed.

Signed-off-by: Evan Owen <kainosnoema@gmail.com>
@lionelbarrow
Copy link
Contributor

This was a pretty egregious error on my part. I introduced this bug in this commit 4 months ago and basically broke the library. I apologize. Thanks a lot for catching this.

lionelbarrow added a commit that referenced this pull request Apr 17, 2014
Add call to wg.Wait() before returning from Serve(), fix server tests
@lionelbarrow lionelbarrow merged commit b369c43 into braintree:master Apr 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants