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

UDP multicast in the cluster does not work #12572

Closed
srdjanarsic opened this issue Apr 21, 2017 · 2 comments
Closed

UDP multicast in the cluster does not work #12572

srdjanarsic opened this issue Apr 21, 2017 · 2 comments
Labels
cluster Issues and PRs related to the cluster subsystem. dgram Issues and PRs related to the dgram subsystem / UDP. doc Issues and PRs related to the documentations. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.

Comments

@srdjanarsic
Copy link

srdjanarsic commented Apr 21, 2017

  • Version: v7.9.0 & v6.9.4
  • Platform: Linux ... x86_64 x86_64 x86_64 GNU/Linux/Centos v7.3
  • Subsystem:

I've tried to connect to UDP multicast from nodejs cluster.
It failed on the second process.

We are getting this error:

dgram.js:503
    throw errnoException(err, 'addMembership');
    ^

Error: addMembership EADDRINUSE
    at exports._errnoException (util.js:1050:11)
    at Socket.addMembership (dgram.js:503:11)
    at Socket.<anonymous> (/install/multicastudp/test2.js:23:15)
    at Object.onceWrapper (events.js:293:19)
    at emitNone (events.js:91:20)
    at Socket.emit (events.js:188:7)
    at startListening (dgram.js:117:10)
    at onHandle (dgram.js:200:9)
    at shared (internal/cluster/child.js:105:3)
    at Worker.send (internal/cluster/child.js:76:7)

Code we used:

const cluster = require('cluster');
const dgram = require('dgram');

const udpPort = 64000;
const addr = '239.0.0.1';

if(cluster.isMaster){

     cluster.fork();
     cluster.fork(); // << this process cause an error

}else{

  console.log("process pid: " + process.pid);

  var udpClient = dgram.createSocket({type:"udp4", reuseAddr:true});

  udpClient.bind(udpPort, function(){
    udpClient.addMembership(addr);
  });

}
@mscdex mscdex added cluster Issues and PRs related to the cluster subsystem. dgram Issues and PRs related to the dgram subsystem / UDP. labels Apr 21, 2017
@mscdex
Copy link
Contributor

mscdex commented Apr 21, 2017

It makes sense to me, since IIRC there is only one udp socket in the master process and the first fork already added membership for that socket.

@bnoordhuis
Copy link
Member

UDP is a bit special with cluster: the socket is created in the master process and each worker gets a copy (as in dup(2), except the actual mechanism is sendmsg(2) with a SCM_RIGHTS vector.)

The copies still refer to the same socket though, so you get the same effect as when you call .addMembership() twice in a single process:

dgram.createSocket('udp4').bind(12345, function() {
  this.addMembership('239.0.0.1');  // ok
  this.addMembership('239.0.0.1');  // EADDRINUSE
});

As a workaround, set up your script so that only one worker calls .addMembership(); that change should automatically carry over to the other workers.

The cluster module could track simple cases like your test case but it gets complex fast when different workers join or leave different multicast groups, with plenty potential for unexpected interactions.

My gut reaction is that it is better to document the workaround than trying to fix it up and get trapped in a tar pit of edge cases.

@Trott Trott added doc Issues and PRs related to the documentations. help wanted Issues that need assistance from volunteers or PRs that need help to proceed. labels Aug 2, 2017
watilde added a commit to watilde/node that referenced this issue Oct 22, 2017
jasnell added a commit to jasnell/node that referenced this issue Oct 19, 2018
targos pushed a commit that referenced this issue Oct 24, 2018
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 26, 2018
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 26, 2018
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 26, 2018
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
rvagg pushed a commit that referenced this issue Nov 28, 2018
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
rvagg pushed a commit that referenced this issue Nov 28, 2018
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
rvagg pushed a commit that referenced this issue Nov 28, 2018
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
MylesBorins pushed a commit that referenced this issue Nov 29, 2018
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
MylesBorins pushed a commit that referenced this issue Dec 26, 2018
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
rvagg pushed a commit that referenced this issue Feb 28, 2019
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
BethGriggs pushed a commit that referenced this issue Mar 7, 2019
Fixes: #12572
Refs: #16240

PR-URL: #23746
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
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. dgram Issues and PRs related to the dgram subsystem / UDP. doc Issues and PRs related to the documentations. help wanted Issues that need assistance from volunteers or PRs that need help to proceed.
Projects
None yet
Development

No branches or pull requests

4 participants