| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4b1f730 commit 9fd6b5e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1911,7 +1911,10 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 1911 | 1911 | nread = buf.size(); | |
| 1912 | 1912 | stream_buf_offset_ = 0; | |
| 1913 | 1913 | stream_buf_ab_.Reset(); | |
| 1914 | - DecrementCurrentSessionMemory(stream_buf_offset_); | ||
| 1914 | + | ||
| 1915 | + // We have now fully processed the stream_buf_ input chunk (by moving the | ||
| 1916 | + // remaining part into buf, which will be accounted for below). | ||
| 1917 | + DecrementCurrentSessionMemory(stream_buf_.len); | ||
| 1915 | 1918 | } | |
| 1916 | 1919 | ||
| 1917 | 1920 | // Shrink to the actual amount of used data. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,55 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + if (!common.hasCrypto) | ||
| 4 | + common.skip('missing crypto'); | ||
| 5 | + const fixtures = require('../common/fixtures'); | ||
| 6 | + const http2 = require('http2'); | ||
| 7 | + | ||
| 8 | + // Regression test for https://github.com/nodejs/node/issues/29223. | ||
| 9 | + // There was a "leak" in the accounting of session memory leading | ||
| 10 | + // to streams eventually failing with NGHTTP2_ENHANCE_YOUR_CALM. | ||
| 11 | + | ||
| 12 | + const server = http2.createSecureServer({ | ||
| 13 | + key: fixtures.readKey('agent2-key.pem'), | ||
| 14 | + cert: fixtures.readKey('agent2-cert.pem'), | ||
| 15 | + }); | ||
| 16 | + | ||
| 17 | + // Simple server that sends 200k and closes the stream. | ||
| 18 | + const data200k = 'a'.repeat(200 * 1024); | ||
| 19 | + server.on('stream', (stream) => { | ||
| 20 | + stream.write(data200k); | ||
| 21 | + stream.end(); | ||
| 22 | + }); | ||
| 23 | + | ||
| 24 | + server.listen(0, common.mustCall(() => { | ||
| 25 | + const client = http2.connect(`https://localhost:${server.address().port}`, { | ||
| 26 | + ca: fixtures.readKey('agent2-cert.pem'), | ||
| 27 | + servername: 'agent2', | ||
| 28 | + | ||
| 29 | + // Set maxSessionMemory to 1MB so the leak causes errors faster. | ||
| 30 | + maxSessionMemory: 1 | ||
| 31 | + }); | ||
| 32 | + | ||
| 33 | + // Repeatedly create a new stream and read the incoming data. Even though we | ||
| 34 | + // only have one stream active at a time, prior to the fix for #29223, | ||
| 35 | + // session memory would steadily increase and we'd eventually hit the 1MB | ||
| 36 | + // maxSessionMemory limit and get NGHTTP2_ENHANCE_YOUR_CALM errors trying to | ||
| 37 | + // create new streams. | ||
| 38 | + let streamsLeft = 50; | ||
| 39 | + function newStream() { | ||
| 40 | + const stream = client.request({ ':path': '/' }); | ||
| 41 | + | ||
| 42 | + stream.on('data', () => { }); | ||
| 43 | + | ||
| 44 | + stream.on('close', () => { | ||
| 45 | + if (streamsLeft-- > 0) { | ||
| 46 | + newStream(); | ||
| 47 | + } else { | ||
| 48 | + client.destroy(); | ||
| 49 | + server.close(); | ||
| 50 | + } | ||
| 51 | + }); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + newStream(); | ||
| 55 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments