-
-
Notifications
You must be signed in to change notification settings - Fork 36.6k
http2: fix onread assert when destroying session from stream handler #65116
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
Open
sankalpsthakur
wants to merge
3
commits into
nodejs:main
Choose a base branch
from
sankalpsthakur:fix/64850-http2-onread-assert
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
test/parallel/test-http2-session-destroy-stream-handler.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| if (!common.hasCrypto) | ||
| common.skip('missing crypto'); | ||
|
|
||
| const http2 = require('http2'); | ||
|
|
||
| // Regression test for https://github.com/nodejs/node/issues/64850 | ||
| // | ||
| // Destroying the session from a 'stream' handler runs (via nextTick drained | ||
| // from MakeCallback) while nghttp2 is still inside mem_recv. Close is deferred | ||
| // for that window; later HEADERS/DATA in the same buffer must not abort with | ||
| // Assertion failed: onread->IsFunction(). | ||
|
|
||
| const STREAMS = 8; | ||
| const BODY = Buffer.alloc(2048, 'a'); | ||
| const ROUNDS = 40; | ||
|
|
||
| const server = http2.createServer({ | ||
| settings: { maxConcurrentStreams: 4 }, | ||
| }); | ||
|
|
||
| server.on('session', (session) => session.on('error', () => {})); | ||
|
|
||
| server.on('stream', (stream) => { | ||
| stream.on('error', () => {}); | ||
| stream.session.destroy(); | ||
| }); | ||
|
|
||
| server.listen(0, '127.0.0.1', common.mustCall(() => { | ||
| const port = server.address().port; | ||
| const origin = `http://127.0.0.1:${port}`; | ||
| let remaining = ROUNDS; | ||
|
|
||
| const round = () => { | ||
| if (remaining-- <= 0) { | ||
| server.close(); | ||
| return; | ||
| } | ||
|
|
||
| const session = http2.connect(origin); | ||
| session.on('error', () => {}); | ||
| session.on('close', () => setImmediate(round)); | ||
|
|
||
| session.on('connect', () => { | ||
| for (let i = 0; i < STREAMS; i++) { | ||
| const stream = session.request({ | ||
| ':path': `/${i}`, | ||
| ':method': 'POST', | ||
| }); | ||
| stream.on('error', () => {}); | ||
| stream.resume(); | ||
| stream.end(BODY); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| round(); | ||
| })); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Nit: This should send REFUSED_STREAM too I think, matching the
session.closedbelow that it's mirroring.Nit because really this code is just defense in depth, and the 2nd chunk here makes it unreachable, but if we ever did reach it somehow, we would want to tell the other peer we haven't processed their stream so they can retry it, rather than silently disappearing.