Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: buffers are not sent over IPC with a socket #6951

Closed
wants to merge 1 commit into from

Conversation

timkuijsten
Copy link
Contributor

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.

@nodejs-github-bot nodejs-github-bot added the doc Issues and PRs related to the documentations. label May 24, 2016
@@ -856,7 +856,9 @@ Applications should avoid using such messages or listening for
The optional `sendHandle` argument that may be passed to `child.send()` is for
passing a TCP server or socket object to the child process. The child will
receive the object as the second argument passed to the callback function
registered on the [`process.on('message')`][] event.
registered on the [`process.on('message')`][] event. Any data that is received
and buffered in the socket will not be sent to the child, only data that arrives
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence seems incomplete. I would just stop after "will not be sent to the child." and remove the rest.

@cjihrig
Copy link
Contributor

cjihrig commented May 24, 2016

One comment, but LGTM.

@timkuijsten
Copy link
Contributor Author

updated + added a new finding while trying to work around the issue myself.

registered on the [`process.on('message')`][] event.
registered on the [`process.on('message')`][] event. Any data that is received
and buffered in the socket will not be sent to the child. The socket in the parent
will be closed right after it is sent to the child.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you seen the keepOpen option to send()?

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.
@timkuijsten
Copy link
Contributor Author

No I had not, tnx! Updated the diff.

@addaleax addaleax added the child_process Issues and PRs related to the child_process subsystem. label May 29, 2016
@addaleax
Copy link
Member

LGTM, landing this…

@addaleax
Copy link
Member

Landed in 5207526. Thank you!

@addaleax addaleax closed this May 29, 2016
addaleax pushed a commit that referenced this pull request May 29, 2016
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.

PR-URL: #6951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Fishrock123 pushed a commit to Fishrock123/node that referenced this pull request May 30, 2016
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.

PR-URL: nodejs#6951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
rvagg pushed a commit that referenced this pull request Jun 2, 2016
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.

PR-URL: #6951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@MylesBorins
Copy link
Contributor

this is not landing cleanly, and I'm not 100% it applies to v4.x

Please backport if neccessary

@timkuijsten
Copy link
Contributor Author

this is not landing cleanly, and I'm not 100% it applies to v4.x

It does apply to v4.x as well:

$ 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

MylesBorins pushed a commit that referenced this pull request Jul 12, 2016
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.

PR-URL: #6951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this pull request Jul 12, 2016
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.

PR-URL: #6951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@MylesBorins MylesBorins mentioned this pull request Jul 12, 2016
MylesBorins pushed a commit that referenced this pull request Jul 14, 2016
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.

PR-URL: #6951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MylesBorins pushed a commit that referenced this pull request Jul 14, 2016
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.

PR-URL: #6951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants