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

fix: set session as gracefully closing on goaway frame #90

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions source/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,12 @@ class Agent extends EventEmitter {
session.destroy();
});

session.once('goaway', () => {
// Prevent session from being used for new requests.
// The session will eventually emit either an 'error' or 'close' event.
session[kGracefullyClosing] = true;
Copy link
Owner

Choose a reason for hiding this comment

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

Please use gracefullyClose(session) instead

Copy link
Owner

Choose a reason for hiding this comment

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

Can you add a comment to the spec as well please?

Copy link
Author

Choose a reason for hiding this comment

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

@szmarczak My only concern with using gracefullyClose(session) is that session.close() may be fired multiple times but this condition appears to be handled here so I will update it to use gracefullyClose.

As for the spec, do you mean the comment in the source code?

Copy link
Owner

Choose a reason for hiding this comment

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

No, I mean the HTTP/2 RFC

Copy link
Author

Choose a reason for hiding this comment

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

Does this work?

// See https://datatracker.ietf.org/doc/html/rfc7540#section-6.8 

// There is an inherent race condition between an endpoint starting new streams and the remote sending a GOAWAY frame.
// Receivers of a GOAWAY frame MUST NOT open additional streams on the connection, although a new connection can be established for new streams.

Copy link
Author

Choose a reason for hiding this comment

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

Change made to reference RFC

Copy link
Author

Choose a reason for hiding this comment

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

@szmarczak Do you need me to do anything else for this?

});

session.once('close', () => {
this._sessionCount--;

Expand Down