-
Notifications
You must be signed in to change notification settings - Fork 455
Clean up closed connections #283
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,8 +56,15 @@ Agent.prototype.close = function(err) { | |
| }; | ||
|
|
||
| Agent.prototype._cleanup = function() { | ||
|
|
||
| // Only clean up once if the stream emits both 'end' and 'close'. | ||
| if (this.closed) return; | ||
|
|
||
| this.closed = true; | ||
|
|
||
| this.backend.agentsCount--; | ||
| if (!this.stream.isServer) this.backend.remoteAgentsCount--; | ||
|
|
||
| // Clean up doc subscription streams | ||
| for (var collection in this.subscribedDocs) { | ||
| var docs = this.subscribedDocs[collection]; | ||
|
|
@@ -258,12 +265,10 @@ Agent.prototype._open = function() { | |
| agent._handleMessage(request.data, callback); | ||
| }); | ||
| }); | ||
|
|
||
| this.stream.on('end', function() { | ||
| agent.backend.agentsCount--; | ||
| if (!agent.stream.isServer) agent.backend.remoteAgentsCount--; | ||
| agent._cleanup(); | ||
| }); | ||
|
|
||
| var cleanup = agent._cleanup.bind(agent); | ||
| this.stream.on('end', cleanup); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion by Nate for the future, paraphrased by me:
|
||
| this.stream.on('close', cleanup); | ||
| }; | ||
|
|
||
| // Check a request to see if its valid. Returns an error if there's a problem. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, this will be defensive against 'end' accidentally being emitted twice by the stream too, which the old code didn't do.