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

http2: simplify subsequent rstStream calls #16753

Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,8 @@ class Http2Session extends EventEmitter {

const state = stream[kState];
if (state.rst) {
// rst has already been called, do not call again,
// skip straight to destroy
stream.destroy();
// rst has already been called by self or peer,
// do not call again
Copy link
Member Author

Choose a reason for hiding this comment

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

Also to expand on what this says, we can't throw here because it's possible we received an RST frame from the remote peer and are getting ready to destroy but have not done that yet, so the user code calls rstStream in the meantime — that's where it should just gracefully exit rather than throw.

Copy link
Member

Choose a reason for hiding this comment

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

Can you assert(stream.destroyed); here instead? If I understand correctly, that should always be true?

Copy link
Member Author

@apapirovski apapirovski Nov 4, 2017

Choose a reason for hiding this comment

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

Not necessarily since the destruction gets scheduled using setImmediate or process.nextTick. (Also when stream.destroyed then this function will throw further up above.)

return;
}
state.rst = true;
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-http2-client-rststream-before-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ server.on('listening', common.mustCall(() => {
// make sure that destroy is called
req._destroy = common.mustCall(req._destroy.bind(req));

// second call doesn't do anything
assert.doesNotThrow(() => client.rstStream(req, 8));
assert.strictEqual(req.rstCode, 0);

req.on('streamClosed', common.mustCall((code) => {
assert.strictEqual(req.destroyed, true);
assert.strictEqual(code, 0);
Expand Down