summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-max-session-memory-leak.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-05-26 17:48:47 +0200
committerAnna Henningsen <anna@addaleax.net>2019-05-29 12:26:38 +0200
commitb84b4d8c7dc957dd630a66ee372c6f29e173e98d (patch)
tree4d541fd47add0dbf1bb9599554b21cb35297d715 /test/parallel/test-http2-max-session-memory-leak.js
parenteb4c1d5663ff7089badfeaf37dbe246df60607e9 (diff)
downloadandroid-node-v8-b84b4d8c7dc957dd630a66ee372c6f29e173e98d.tar.gz
android-node-v8-b84b4d8c7dc957dd630a66ee372c6f29e173e98d.tar.bz2
android-node-v8-b84b4d8c7dc957dd630a66ee372c6f29e173e98d.zip
http2: fix tracking received data for maxSessionMemory
Track received data correctly. Specifically, for the buffer that is used for receiving data, we previously would try to increment the current memory usage by its length, and later decrement it by that, but in the meantime the buffer had been turned over to V8 and its length reset to zero. This gave the impression that more and more memory was consumed by the HTTP/2 session when it was in fact not. Fixes: https://github.com/nodejs/node/issues/27416 Refs: https://github.com/nodejs/node/pull/26207 PR-URL: https://github.com/nodejs/node/pull/27914 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'test/parallel/test-http2-max-session-memory-leak.js')
-rw-r--r--test/parallel/test-http2-max-session-memory-leak.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/parallel/test-http2-max-session-memory-leak.js b/test/parallel/test-http2-max-session-memory-leak.js
new file mode 100644
index 0000000000..b066ca80bc
--- /dev/null
+++ b/test/parallel/test-http2-max-session-memory-leak.js
@@ -0,0 +1,46 @@
+'use strict';
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+const http2 = require('http2');
+
+// Regression test for https://github.com/nodejs/node/issues/27416.
+// Check that received data is accounted for correctly in the maxSessionMemory
+// mechanism.
+
+const bodyLength = 8192;
+const maxSessionMemory = 1; // 1 MB
+const requestCount = 1000;
+
+const server = http2.createServer({ maxSessionMemory });
+server.on('stream', (stream) => {
+ stream.respond();
+ stream.end();
+});
+
+server.listen(common.mustCall(() => {
+ const client = http2.connect(`http://localhost:${server.address().port}`, {
+ maxSessionMemory
+ });
+
+ function request() {
+ return new Promise((resolve, reject) => {
+ const stream = client.request({
+ ':method': 'POST',
+ 'content-length': bodyLength
+ });
+ stream.on('error', reject);
+ stream.on('response', resolve);
+ stream.end('a'.repeat(bodyLength));
+ });
+ }
+
+ (async () => {
+ for (let i = 0; i < requestCount; i++) {
+ await request();
+ }
+
+ client.close();
+ server.close();
+ })().then(common.mustCall());
+}));