Skip to content

Commit 109a38d

Browse files
ywave620RafaelGSS
authored andcommitted
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: #47244 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 81ec3f3 commit 109a38d

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/node_http2.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,7 @@ int Http2Session::OnFrameNotSent(nghttp2_session* handle,
10721072
// Do not report if the frame was not sent due to the session closing
10731073
if (error_code == NGHTTP2_ERR_SESSION_CLOSING ||
10741074
error_code == NGHTTP2_ERR_STREAM_CLOSED ||
1075-
error_code == NGHTTP2_ERR_STREAM_CLOSING ||
1076-
session->js_fields_->frame_error_listener_count == 0) {
1075+
error_code == NGHTTP2_ERR_STREAM_CLOSING) {
10771076
// Nghttp2 contains header limit of 65536. When this value is exceeded the
10781077
// pipeline is stopped and we should remove the current headers reference
10791078
// to destroy the session completely.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
const http2 = require('http2');
7+
const assert = require('assert');
8+
const {
9+
DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE,
10+
NGHTTP2_CANCEL,
11+
} = http2.constants;
12+
13+
const headerSize = DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE;
14+
const timeout = common.platformTimeout(2_000);
15+
const timer = setTimeout(() => assert.fail(`http2 client timedout
16+
when server can not manage to send a header of size ${headerSize}`), timeout);
17+
18+
const server = http2.createServer((req, res) => {
19+
res.setHeader('foobar', 'a'.repeat(DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE));
20+
res.end();
21+
});
22+
23+
server.listen(0, common.mustCall(() => {
24+
const clientSession = http2.connect(`http://localhost:${server.address().port}`);
25+
clientSession.on('close', common.mustCall());
26+
clientSession.on('remoteSettings', send);
27+
28+
function send() {
29+
const stream = clientSession.request({ ':path': '/' });
30+
stream.on('close', common.mustCall(() => {
31+
assert.strictEqual(stream.rstCode, NGHTTP2_CANCEL);
32+
clearTimeout(timer);
33+
server.close();
34+
}));
35+
36+
stream.end();
37+
}
38+
}));

0 commit comments

Comments
 (0)