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

Clean up closed connections #283

Merged
merged 3 commits into from
Apr 10, 2019
Merged

Clean up closed connections #283

merged 3 commits into from
Apr 10, 2019

Conversation

curran
Copy link
Contributor

@curran curran commented Apr 9, 2019

The intention here is to resolve #282.

As of now this is a rough first pass. I have not tested or verified if this works yet.

@gkubisa Does this approach seem to make sense?

@coveralls
Copy link

coveralls commented Apr 9, 2019

Coverage Status

Coverage increased (+0.003%) to 95.906% when pulling ef236fa on curran:patch-12 into 5394fa4 on share:master.

@gkubisa
Copy link
Contributor

gkubisa commented Apr 9, 2019

The general idea is good, however, as it is, the agent counts would be decremented twice for streams that emit both end and close events.

I'd move agent counting to Agent#_cleanup and start that method with if (this.closed) return;.

@curran curran changed the title WIP Clean up closed connections Clean up closed connections Apr 9, 2019
@curran
Copy link
Contributor Author

curran commented Apr 9, 2019

Thanks @gkubisa for the guidance. I implemented it as you suggested, and also added tests.

I believe this solves #282.

This PR, by the way, would unblock merging of #281

Kindly requesting review by @ericyhwang or @nateps . Thanks!

Copy link
Contributor

@gkubisa gkubisa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me. It certainly makes the agent cleanup more reliable.

@gkubisa
Copy link
Contributor

gkubisa commented Apr 9, 2019

I've just merged this code into the Teamwork fork of ShareDB.

Copy link
Contributor

@ericyhwang ericyhwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, and thanks for writing a test, too!

@@ -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;
Copy link
Contributor

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.

});

var cleanup = agent._cleanup.bind(agent);
this.stream.on('end', cleanup);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion by Nate for the future, paraphrased by me:

In the future, we should consider not reacting to 'end', and only reacting to 'close'. He says that Share originally reacted to 'end' since the original stream implementation by Avital emitted both 'end' and 'close', since that was the recommendation for old versions of Node.

Nowadays, we probably no longer need to do that.

@ericyhwang ericyhwang merged commit 70ee4ea into share:master Apr 10, 2019
@ericyhwang
Copy link
Contributor

This is published as [email protected]

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.

[ERR_STREAM_DESTROYED] seems sharedb is not closing connections
4 participants