The current behavior when sending a net.Socket object to a child process using child_process.ChildProcess.send() is to close the socket in the parent. This way, only the socket receiver can read and write to it.
Problem: in some use-cases, a user may want to have BOTH parent and child to write to the TCP socket. For instance, I'm developing an app where a process writes data to the socket, whereas another one writes metadata. Sharing the socket in C, not in Node.js (currently).
The enhancement I propose is to add an optional keepOpen parameter to specify whether the parent should keep the socket open or not (it would default to false to keep existing behavior).
const child = require('child_process').fork('child.js');
const server = require('net').createServer();
server.listen(1234).on('connection', function (socket) {
child.send('socket', socket, { keepOpen: true });
// Currently this crashes with: "Error: This socket is closed."
socket.write('-- hello from parent --');
});
What I'm asking here is whether this is an acceptable enhancement or not. If it is, I'll start working on a clean pull request.
The current behavior when sending a
net.Socketobject to a child process usingchild_process.ChildProcess.send()is to close the socket in the parent. This way, only the socket receiver can read and write to it.Problem: in some use-cases, a user may want to have BOTH parent and child to write to the TCP socket. For instance, I'm developing an app where a process writes data to the socket, whereas another one writes metadata. Sharing the socket in C, not in Node.js (currently).
The enhancement I propose is to add an optional
keepOpenparameter to specify whether the parent should keep the socket open or not (it would default tofalseto keep existing behavior).What I'm asking here is whether this is an acceptable enhancement or not. If it is, I'll start working on a clean pull request.