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

Listen to CloseNotifier in stream handler. #382

Closed
wants to merge 1 commit into from

Conversation

spynup
Copy link

@spynup spynup commented Jul 22, 2015

Problem:

context.Stream() listens to the closeNotifier, which gives the impression that context.Stream() will return as soon as a client disconnects. Unfortunately, it doesn't!

This example code furthers the impression with the defer closeListener(roomid, listener) which one would expect to be called when a client navigates away, which is not the case. In fact, it's only called on the next message that's sent to the room after said client exits.

This is because c.SSEvent("message", <-listener) blocks indefinitely until a message comes in, so will not return and yield to c.Stream()'s select that catches the closeNotify. This means that if a client navigates away, the server never notices and cleans up.

Fix: Also listen to CloseNotifier inside stream handler. This causes the step() function to return immediately when the client goes away and allows the cleanup to run. Updating this example should make it more clear, I think!

Problem:

context.Stream() already listens to the closeNotifier, which gives the impression that context.Stream() will return as soon as a client disconnects.  Unfortunately, it doesn't!

This example code furthers the impression with the defer closeListener(roomid, listener) which one would expect to be called when a client navigates away, which is not the case.  In fact, it's only called on the next message that's sent to the room after said client exits. 

This is because c.SSEvent("message", <-listener) blocks indefinitely until a message comes in, so will not return and yield to c.Stream()'s select that catches the closeNotify.  This means that if a client navigates away, the server never notices and cleans up.

Fix: Also listen to CloseNotifier inside stream handler.  This causes the step() function to return immediately when the client goes away and allows the cleanup to run.  Updating this example should make it more clear, I think!
@se77en
Copy link
Contributor

se77en commented Feb 14, 2016

Looks nice

@thinkerou
Copy link
Member

@appleboy can you merged the pr?

@appleboy
Copy link
Member

@thinkerou I can't merge and update the branch. @javierprovecho Please help to merge.

@thinkerou thinkerou added this to the 1.4 milestone Feb 20, 2019
@thinkerou thinkerou modified the milestones: 1.4, 1.5 Mar 1, 2019
@thinkerou
Copy link
Member

@spynup thanks!

@thinkerou thinkerou closed this Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants