diff options
author | Anna Henningsen <anna@addaleax.net> | 2021-05-19 00:25:15 +0300 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2021-05-31 22:34:51 +0300 |
commit | 717a8b63e1a4d1f1cbb50e7b02b9188fc346703a (patch) | |
tree | d6a0217d3130631f76431c21c9ac2420695d8c62 /test | |
parent | 7a9d0fd5a92e3186ac3d2e7dedb46b3617352a2d (diff) |
child_process: retain reference to data with advanced serialization
Do the same thing we do for other streams, and retain a reference to
the Buffer that was sent over IPC while the write request is active,
so that it doesn’t get garbage collected while the data is still in
flight.
(This is a good example of why it’s a bad idea that we’re not re-using
the general streams implementation for IPC and instead maintain
separate usage of the low-level I/O primitives.)
Fixes: https://github.com/nodejs/node/issues/34797
PR-URL: https://github.com/nodejs/node/pull/38728
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-child-process-advanced-serialization-largebuffer.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/parallel/test-child-process-advanced-serialization-largebuffer.js b/test/parallel/test-child-process-advanced-serialization-largebuffer.js new file mode 100644 index 00000000000..4e80bce4057 --- /dev/null +++ b/test/parallel/test-child-process-advanced-serialization-largebuffer.js @@ -0,0 +1,27 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const child_process = require('child_process'); + +// Regression test for https://github.com/nodejs/node/issues/34797 +const eightMB = 8 * 1024 * 1024; + +if (process.argv[2] === 'child') { + for (let i = 0; i < 4; i++) { + process.send(new Uint8Array(eightMB).fill(i)); + } +} else { + const child = child_process.spawn(process.execPath, [__filename, 'child'], { + stdio: ['inherit', 'inherit', 'inherit', 'ipc'], + serialization: 'advanced' + }); + const received = []; + child.on('message', common.mustCall((chunk) => { + assert.deepStrictEqual(chunk, new Uint8Array(eightMB).fill(chunk[0])); + + received.push(chunk[0]); + if (received.length === 4) { + assert.deepStrictEqual(received, [0, 1, 2, 3]); + } + }, 4)); +} |