-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
http2: fix session memory accounting after pausing #30684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
mikelehen
wants to merge
1
commit into
nodejs:master
from
mikelehen:mikelehen/fix-http2-session-memory-accounting-leak
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
55 changes: 55 additions & 0 deletions
55
test/parallel/test-http2-large-writes-session-memory-leak.js
This file contains hidden or 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,55 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const fixtures = require('../common/fixtures'); | ||
const http2 = require('http2'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/29223. | ||
// There was a "leak" in the accounting of session memory leading | ||
// to streams eventually failing with NGHTTP2_ENHANCE_YOUR_CALM. | ||
|
||
const server = http2.createSecureServer({ | ||
key: fixtures.readKey('agent2-key.pem'), | ||
cert: fixtures.readKey('agent2-cert.pem'), | ||
}); | ||
|
||
// Simple server that sends 200k and closes the stream. | ||
const data200k = 'a'.repeat(200 * 1024); | ||
server.on('stream', (stream) => { | ||
stream.write(data200k); | ||
stream.end(); | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = http2.connect(`https://localhost:${server.address().port}`, { | ||
ca: fixtures.readKey('agent2-cert.pem'), | ||
servername: 'agent2', | ||
|
||
// Set maxSessionMemory to 1MB so the leak causes errors faster. | ||
maxSessionMemory: 1 | ||
}); | ||
|
||
// Repeatedly create a new stream and read the incoming data. Even though we | ||
// only have one stream active at a time, prior to the fix for #29223, | ||
// session memory would steadily increase and we'd eventually hit the 1MB | ||
// maxSessionMemory limit and get NGHTTP2_ENHANCE_YOUR_CALM errors trying to | ||
// create new streams. | ||
let streamsLeft = 50; | ||
function newStream() { | ||
const stream = client.request({ ':path': '/' }); | ||
|
||
stream.on('data', () => { }); | ||
|
||
stream.on('close', () => { | ||
if (streamsLeft-- > 0) { | ||
newStream(); | ||
} else { | ||
client.destroy(); | ||
server.close(); | ||
} | ||
}); | ||
} | ||
|
||
newStream(); | ||
})); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.