-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #34797 PR-URL: #38728 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
- Loading branch information
1 parent
f9693cf
commit 55ea29e
Showing
2 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
27 changes: 27 additions & 0 deletions
27
test/parallel/test-child-process-advanced-serialization-largebuffer.js
This file contains 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,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)); | ||
} |