Skip to content

Commit

Permalink
src,http2: ensure cleanup if a frame is not sent
Browse files Browse the repository at this point in the history
Call to JS and close the session if a frame is not sent
even there is no frameError listener registered by user.

PR-URL: #47244
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
  • Loading branch information
ywave620 authored and danielleadams committed Jul 6, 2023
1 parent 53d9eb5 commit a7620d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions test/parallel/test-h2-large-header-cause-client-to-hangup.js
Original file line number Diff line number Diff line change
@@ -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();
}
}));

0 comments on commit a7620d1

Please sign in to comment.