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

grpc-js: server: cull closed sessions from list, check for closed in tryShutdown #1467

Merged
merged 2 commits into from
Jun 15, 2020

Conversation

murgatroid99
Copy link
Member

As currently written, the sessions field tracks every HTTP/2 session that has ever been established with the server, which can grow without bound. If we remove the ones that are closed, it should be bounded by network connection limits. The check for session.closed in tryShutdown should avoid potential race conditions, where we get to that line and the close event is pending but has not fired yet.

I think this will fix #1458.

pendingChecks += this.sessions.size;
this.sessions.forEach((session) => {
session.close(maybeCallback);
if (!session.closed) {
pendingChecks += 1;
Copy link
Member

Choose a reason for hiding this comment

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

Took me a second to realize why this was added. I don't like the fact there's a disjoint between adding a new pending action, and incrementing this counter: this feels brittle. But I don't see a way to do this without over engineering it completely:

  function addAction(action) {
    pendingChecks++;
    action(maybeCallback);
}

[...]

addAction(callback => session.close(callback));

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if this is worth changing here but I'm glad you brought it up because there was actually an error. See the new commit.

@murgatroid99 murgatroid99 merged commit a6101f3 into grpc:master Jun 15, 2020
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.

@grpc/grpc-js: tryShutdown freeze app
2 participants