forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: do not crash on stream listener removal w/ destroyed session
Do not crash when the session is no longer available. Fixes: nodejs#29457 PR-URL: nodejs#29459 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
2 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
31 changes: 31 additions & 0 deletions
31
test/parallel/test-http2-stream-removelisteners-after-close.js
This file contains 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,31 @@ | ||
'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/29457: | ||
// HTTP/2 stream event listeners can be added and removed after the | ||
// session has been destroyed. | ||
|
||
const server = http2.createServer((req, res) => { | ||
res.end('Hi!\n'); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = http2.connect(`http://localhost:${server.address().port}`); | ||
const headers = { ':path': '/' }; | ||
const req = client.request(headers); | ||
|
||
req.on('close', common.mustCall(() => { | ||
req.removeAllListeners(); | ||
req.on('priority', common.mustNotCall()); | ||
server.close(); | ||
})); | ||
|
||
req.on('priority', common.mustNotCall()); | ||
req.on('error', common.mustCall()); | ||
|
||
client.destroy(); | ||
})); |