-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: #29457 PR-URL: #29459 Backport-PR-URL: #29619 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
1 parent
c74c6a5
commit 36a0e9a
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(); | ||
})); |