src,http2: ensure cleanup if a frame is not sent

Call to JS and close the session if a frame is not sent
even there is no frameError listener registered by user.

PR-URL: https://github.com/nodejs/node/pull/47244
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
ywave620 2023-03-30 20:40:45 +08:00 committed by GitHub
parent 65b79aba0f
commit 18e1f3c3a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View File

@ -1072,8 +1072,7 @@ int Http2Session::OnFrameNotSent(nghttp2_session* handle,
// Do not report if the frame was not sent due to the session closing
if (error_code == NGHTTP2_ERR_SESSION_CLOSING ||
error_code == NGHTTP2_ERR_STREAM_CLOSED ||
error_code == NGHTTP2_ERR_STREAM_CLOSING ||
session->js_fields_->frame_error_listener_count == 0) {
error_code == NGHTTP2_ERR_STREAM_CLOSING) {
// Nghttp2 contains header limit of 65536. When this value is exceeded the
// pipeline is stopped and we should remove the current headers reference
// to destroy the session completely.

View File

@ -0,0 +1,38 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const assert = require('assert');
const {
DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE,
NGHTTP2_CANCEL,
} = http2.constants;
const headerSize = DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE;
const timeout = common.platformTimeout(2_000);
const timer = setTimeout(() => assert.fail(`http2 client timedout
when server can not manage to send a header of size ${headerSize}`), timeout);
const server = http2.createServer((req, res) => {
res.setHeader('foobar', 'a'.repeat(DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE));
res.end();
});
server.listen(0, common.mustCall(() => {
const clientSession = http2.connect(`http://localhost:${server.address().port}`);
clientSession.on('close', common.mustCall());
clientSession.on('remoteSettings', send);
function send() {
const stream = clientSession.request({ ':path': '/' });
stream.on('close', common.mustCall(() => {
assert.strictEqual(stream.rstCode, NGHTTP2_CANCEL);
clearTimeout(timer);
server.close();
}));
stream.end();
}
}));