-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: propagate session destroy code to streams
Currently, when an HTTP2 session is destroyed with a code, that code is not propagated to the destroy() call of the session's streams. This commit forwards any code used to destroy a session to its corresponding streams. PR-URL: #28435 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 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
54 changes: 54 additions & 0 deletions
54
test/parallel/test-http2-propagate-session-destroy-code.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,54 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
const server = http2.createServer(); | ||
const errRegEx = /Session closed with error code 7/; | ||
const destroyCode = http2.constants.NGHTTP2_REFUSED_STREAM; | ||
|
||
server.on('error', common.mustNotCall()); | ||
|
||
server.on('session', (session) => { | ||
session.on('close', common.mustCall()); | ||
session.on('error', common.mustCall((err) => { | ||
assert(errRegEx.test(err)); | ||
assert.strictEqual(session.closed, false); | ||
assert.strictEqual(session.destroyed, true); | ||
})); | ||
|
||
session.on('stream', common.mustCall((stream) => { | ||
stream.on('error', common.mustCall((err) => { | ||
assert.strictEqual(session.closed, false); | ||
assert.strictEqual(session.destroyed, true); | ||
assert(errRegEx.test(err)); | ||
assert.strictEqual(stream.rstCode, destroyCode); | ||
})); | ||
|
||
session.destroy(destroyCode); | ||
})); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const session = http2.connect(`http://localhost:${server.address().port}`); | ||
|
||
session.on('error', common.mustCall((err) => { | ||
assert(errRegEx.test(err)); | ||
assert.strictEqual(session.closed, false); | ||
assert.strictEqual(session.destroyed, true); | ||
})); | ||
|
||
const stream = session.request({ [http2.constants.HTTP2_HEADER_PATH]: '/' }); | ||
|
||
stream.on('error', common.mustCall((err) => { | ||
assert(errRegEx.test(err)); | ||
assert.strictEqual(stream.rstCode, destroyCode); | ||
})); | ||
|
||
stream.on('close', common.mustCall(() => { | ||
server.close(); | ||
})); | ||
})); |