-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: let http2 streams end after session close
After the stream has been marked as closed by the nghttp2 stack, there might be still pending data to be sent: trailing headers is an example of this. In that case, avoid reentering the nghttp2 stack synchronously to allow the data to be written before actually closing the stream. Fixes: #42713 PR-URL: #45153 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> (cherry picked from commit 71bdecb)
- Loading branch information
1 parent
25307a3
commit edb561c
Showing
2 changed files
with
60 additions
and
0 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
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,49 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
|
||
const { | ||
HTTP2_HEADER_PATH, | ||
HTTP2_HEADER_STATUS, | ||
HTTP2_HEADER_METHOD, | ||
} = http2.constants; | ||
|
||
const server = http2.createServer(); | ||
server.on('stream', common.mustCall((stream) => { | ||
server.close(); | ||
stream.session.close(); | ||
stream.on('wantTrailers', common.mustCall(() => { | ||
stream.sendTrailers({ xyz: 'abc' }); | ||
})); | ||
|
||
stream.respond({ [HTTP2_HEADER_STATUS]: 200 }, { waitForTrailers: true }); | ||
stream.write('some data'); | ||
stream.end(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const port = server.address().port; | ||
const client = http2.connect(`http://localhost:${port}`); | ||
client.socket.on('close', common.mustCall()); | ||
const req = client.request({ | ||
[HTTP2_HEADER_PATH]: '/', | ||
[HTTP2_HEADER_METHOD]: 'POST' | ||
}); | ||
req.end(); | ||
req.on('response', common.mustCall()); | ||
let data = ''; | ||
req.on('data', (chunk) => { | ||
data += chunk; | ||
}); | ||
req.on('end', common.mustCall(() => { | ||
assert.strictEqual(data, 'some data'); | ||
})); | ||
req.on('trailers', common.mustCall((headers) => { | ||
assert.strictEqual(headers.xyz, 'abc'); | ||
})); | ||
req.on('close', common.mustCall()); | ||
})); |