Skip to content

doc: buffers are not sent over IPC with a socket

Checklist
  • documentation is changed or added
  • the commit message follows commit guidelines
Affected core subsystem(s)

doc/child_process

Description of change

If a socket is sent to a child, any data that is buffered in the socket will not be sent to the child. The child will only receive data from the socket that is sent after the child has the socket.

PoC:

From https://github.com/nodejs/node/pull/6951:

$ node --version
v4.4.7
$ cat m.js
const fork = require('child_process').fork
const net = require('net')

const cp = fork('./child.js')

net.createServer(c => {
  setTimeout(() => {
    cp.send({}, c)
  }, 500) // send the connection after a delay
}).listen(1234, () => {
  net.createConnection(1234, function() {
    var i = 0
    setInterval(() => {
      this.write(`${i++} `)
    }, 100) // start sending data before the connection is sent to the child
  })
})
$ cat child.js 
process.on('message', (m, c) => {
  console.log('child: got connection')
  c.pipe(process.stdout)
})
$ node m.js
child: got connection
4 5 6 7 8 ^C

Merge request reports

Loading