Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

UDP4 socket fails to bind with clustering #2194

@jedsmallwood

Description

@jedsmallwood

It appears that there is a bug with dgram in that subsequent workers fail to bind to the specified port. I did a search and it appears that a similar bug existed in the LearnBoost/cluster project in 0.6.6; LearnBoost/cluster#129

This bug exists in 0.6.2 on OSX at least. The following is some sample code that demonstrates the problem.

var util = require("util"),
  dgram = require("dgram"),
  cluster = require('cluster');

var udp = dgram.createSocket("udp4");
var port = 1190;

if (cluster.isMaster) {
  for (i = 0; i < 2; i++) {
    cluster.fork();
  }
} else {
  util.log("starting udp server on port " + port);
  udp.on("error", function (error) {
    util.log("failed to bind to UDP port - " + error)
  });
  udp.bind(port);
}

Running this code you see the following:

$ node udp-cluster.js
25 Nov 23:05:53 - starting udp server on port 1190
25 Nov 23:05:53 - starting udp server on port 1190
25 Nov 23:05:53 - failed to bind to UDP port - Error: bind EADDRINUSE

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions