-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Fix Shutdown() #25
Fix Shutdown() #25
Conversation
* Add test in sse_test.go for Shutdown() panic and goroutine leak * Avoid panic: don't close `removeClient` (it's useless and it would require a sort of wait group) * Avoid leak: don't block on `removeClient<-` when an HTTP Handler ends because of the client being removed already Shutdown should probably take a Context and return on completion.
The fix does not sound right, and the test is odd. See my comment in #24. |
I don't understand why the test is odd. I would not get it if my app exited quickly enough to actually not shut down, like in other tests. Calling See |
Here is a little more material, hopping it helps:
Ian Lance Taylor
Go Tour
Finally, if you modify the examples a little, you can reproduce the bug using curl as a client:
Code for net_http.go
go http.ListenAndServe(":3000", nil)
time.Sleep(5 * time.Second) // Use this time to run "curl http://localhost:3000/events/channel-1"
s.Shutdown()
time.Sleep(10 * time.Millisecond) // Should panic, now that s.Shutdown() has time to complete In my test, I was trying to:
Is it why it looked odd? I hope it's all clearer now :) Thanks again. |
You have found a very unusual bug, it only fails if the remote client closes the connection while the shutdown is in progress. To explain a bit:
I managed to reproduce it and I managed to fix (I think) the proper way. The wrong part is in ServeHTTP function. I also have found that the Shutdown never really waited on anything to be shut down, also fixing that. I'll be closing this PR because there's a better way to fix it, but this helped me understand the problem. Thanks. |
I've actually found and fixed several other issues, but found it a little difficult to move forward through PR, so decided to keep my fork and use it instead. You can have a look at it if you want to spot other minor mistakes or lacks. |
I took a look, lots of changes. My changes will be a major refactoring, rewriting the server, I'll probably fix some issues and create new ones. I also have a plan to create on connect/disconnect functions. |
This is to fix #24
sse_test.go
for Shutdown() panic and goroutine leakremoveClient
(I think it's useless, and it would require a sort of wait group)removeClient<-
when an HTTP Handler ends because of the client being removed alreadyclient
to signal the client has already been removed. It should be garbage collected if it is never read.Maybe we could make Shutdown work like http.Server.Shutdown : return on completion, and take a context.Context for deadline.