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

net.Server 'connection' callback not invoked after passing handle to forked process #13740

Closed
weekens opened this issue Jun 17, 2017 · 3 comments
Labels
cluster Issues and PRs related to the cluster subsystem. net Issues and PRs related to the net subsystem.

Comments

@weekens
Copy link

weekens commented Jun 17, 2017

I have a test that involves net.Server socket handle transferring functionality (the socket is passed to a forked process). What the test does is:

  1. Creates a TCP server listening on port 8889.
  2. Creates a forked process.
  3. Passes a created TCP server handle to a forked process. The process listens for the 'connection' event on received handle. Upon connection it sends a 'Hello!' message to a connected socket and closes the connection.
  4. Connects with a TCP client to port 8889 and awaits data.
  5. Ensures that the data is 'Hello!', closes the server and kills forked process.

The test fails quite often in an interesting way: a client receives a 'connect' callback, but the forked process does not receive a 'connection' callback, and the test fails with timeout.

I have extracted all my project-related stuff from that test and came up with this small project that reproduces the issue: https://github.com/weekens/nodejs-handle-issue

You can launch the test with the following:

npm install
npm test

The test is repeated 100 times, but on my machine few single launches are enough to reproduce the issue.

The tests produce debug ouput to make it more clear what's happening there.

If I'm doing something wrong in this test - please let me know.

@addaleax addaleax added cluster Issues and PRs related to the cluster subsystem. net Issues and PRs related to the net subsystem. labels Jun 17, 2017
@addaleax
Copy link
Member

/cc @aqrln @lpinca

@bnoordhuis
Copy link
Member

You don't close the server handle after it's been received by the child, do you? If the server socket is alive in both processes, an incoming connection can end up in either one (and that's by design, it's not a bug.)

@weekens
Copy link
Author

weekens commented Jun 19, 2017

@bnoordhuis , yor're right! That was the reason of failure. Thanks a lot!

(Fixed test, now it works).

@weekens weekens closed this as completed Jun 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cluster Issues and PRs related to the cluster subsystem. net Issues and PRs related to the net subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants