GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: set nghttp2_option_set_no_closed_streams · nodejs/node@001881f

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_http2.cc
  • test/parallel
    • test-http2-forget-closed-streams.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_http2.cc‎

Copy file name to clipboardExpand all lines: src/node_http2.cc
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ Http2Scope::~Http2Scope() {
9898
Http2Options::Http2Options(Environment* env, nghttp2_session_type type) {
9999
nghttp2_option_new(&options_);
100100

101+
// Make sure closed connections aren't kept around, taking up memory.
102+
// Note that this breaks the priority tree, which we don't use.
103+
nghttp2_option_set_no_closed_streams(options_, 1);
104+
101105
// We manually handle flow control within a session in order to
102106
// implement backpressure -- that is, we only send WINDOW_UPDATE
103107
// frames to the remote peer as data is actually consumed by user
Collapse file

‎test/parallel/test-http2-forget-closed-streams.js‎

Copy file name to clipboard
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (!common.hasCrypto) {
4+
common.skip('missing crypto');
5+
}
6+
7+
// Issue #23116
8+
// nghttp2 keeps closed stream structures around in memory (couple of hundred
9+
// bytes each) until a session is closed. It does this to maintain the priority
10+
// tree. However, it limits the number of requests that can be made in a
11+
// session before our memory tracking (correctly) kicks in.
12+
// The fix is to tell nghttp2 to forget about closed streams. We don't make use
13+
// of priority anyway.
14+
// Without the fix, this test fails at ~40k requests with an exception:
15+
// Error [ERR_HTTP2_STREAM_ERROR]: Stream closed with error code
16+
// NGHTTP2_ENHANCE_YOUR_CALM
17+
18+
const http2 = require('http2');
19+
const assert = require('assert');
20+
21+
const server = http2.createServer({ maxSessionMemory: 1 });
22+
23+
server.on('session', function(session) {
24+
session.on('stream', function(stream) {
25+
stream.on('end', common.mustCall(function() {
26+
this.respond({
27+
':status': 200
28+
}, {
29+
endStream: true
30+
});
31+
}));
32+
stream.resume();
33+
});
34+
});
35+
36+
server.listen(0, function() {
37+
const client = http2.connect(`http://localhost:${server.address().port}`);
38+
39+
function next(i) {
40+
if (i === 10000) {
41+
client.close();
42+
return server.close();
43+
}
44+
const stream = client.request({ ':method': 'POST' });
45+
stream.on('response', common.mustCall(function(headers) {
46+
assert.strictEqual(headers[':status'], 200);
47+
this.on('close', common.mustCall(() => next(i + 1)));
48+
}));
49+
stream.end();
50+
}
51+
52+
next(0);
53+
});

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.