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

node@0.12.x udp and pm2 #1204

Closed
skoranga opened this issue Apr 24, 2015 · 4 comments
Closed

node@0.12.x udp and pm2 #1204

skoranga opened this issue Apr 24, 2015 · 4 comments

Comments

@skoranga
Copy link

Hi
Looks like pm2 is acting very weird on node@0.12.x when used in cluster mode. On hitting the udp code twice pm2 is orphaning the node process and going stall. This works perfectly fine on plain node.

Created this example to show the issue - https://github.com/skoranga/testudpapp

Any idea what's going on?

-sanjeev

@jshkurti jshkurti self-assigned this Apr 24, 2015
@jshkurti
Copy link
Contributor

Bug confirmed.
It looks like it comes from Node.js itself.
nodejs/node-v0.x-archive#9261

@jshkurti
Copy link
Contributor

Thanks for reporting this, I'm going to try to find a workaround.

@jshkurti
Copy link
Contributor

And it was fixed in joyent/node#v0.12 (https://github.com/joyent/node/pull/8643/files) but it will take a while till it's published.
We can't really do anything about it for now in PM2 :/

Here is a workaround given by one of the Node.js contributors :

var cluster = require('cluster');
var http = require('http');
var dgram = require('dgram');
var numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
  // Fork workers.
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

} else {

  var server = http.createServer(function (request, response) {
    var client = dgram.createSocket("udp4");

    client.bind({exclusive: true}, function() {
      var message = new Buffer("Hello");
      client.send(message, 0, message.length, 80, "google.com", function(err, bytes) {
        client.close();
      });
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.end("Hello World\n");
    });
  });

  server.listen(1337);
}

Important part : client.bind({exclusive: true}

@skoranga
Copy link
Author

thanks, the workaround works. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants