Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2021-05-19 00:25:15 +0300
committerDanielle Adams <adamzdanielle@gmail.com>2021-05-31 22:34:51 +0300
commit717a8b63e1a4d1f1cbb50e7b02b9188fc346703a (patch)
treed6a0217d3130631f76431c21c9ac2420695d8c62 /lib
parent7a9d0fd5a92e3186ac3d2e7dedb46b3617352a2d (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 'lib')
-rw-r--r--lib/internal/child_process/serialization.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/internal/child_process/serialization.js b/lib/internal/child_process/serialization.js
index f61a6b6f255..ec858f401be 100644
--- a/lib/internal/child_process/serialization.js
+++ b/lib/internal/child_process/serialization.js
@@ -12,6 +12,7 @@ const { StringDecoder } = require('string_decoder');
const v8 = require('v8');
const { isArrayBufferView } = require('internal/util/types');
const assert = require('internal/assert');
+const { streamBaseState, kLastWriteWasAsync } = internalBinding('stream_wrap');
const kMessageBuffer = Symbol('kMessageBuffer');
const kJSONBuffer = Symbol('kJSONBuffer');
@@ -82,10 +83,16 @@ const advanced = {
const serializedMessage = ser.releaseBuffer();
const sizeBuffer = Buffer.allocUnsafe(4);
sizeBuffer.writeUInt32BE(serializedMessage.length);
- return channel.writeBuffer(req, Buffer.concat([
+
+ const buffer = Buffer.concat([
sizeBuffer,
serializedMessage,
- ]), handle);
+ ]);
+ const result = channel.writeBuffer(req, buffer, handle);
+ // Mirror what stream_base_commons.js does for Buffer retention.
+ if (streamBaseState[kLastWriteWasAsync])
+ req.buffer = buffer;
+ return result;
},
};