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

UDP4 socket fails to bind with clustering #2194

Closed
jedsmallwood opened this issue Nov 26, 2011 · 20 comments
Closed

UDP4 socket fails to bind with clustering #2194

jedsmallwood opened this issue Nov 26, 2011 · 20 comments
Assignees

Comments

@jedsmallwood
Copy link

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
@AndreasMadsen
Copy link
Member

The problem is that the cluster module only share TCP and not UDP. The worker do bind to the UDP port, but when the next worker initialize the port is all ready used. I'm not sure this is a true bug, or a documentation issue, however I will look intro it in cluster 2.0.

But cluster 2.0 (see #2038 ) won't be pulled in 0.6.x, so somebody (not me) will have to look at it, if it has to be fixed in 0.6.x.

@AndreasMadsen
Copy link
Member

I have looked at the dgram source code. The problem is that dgram module no not support port sharing the same way the net module does. This is out of my abilities as a JavaScript guy. When port sharing is supported i will look at it again.

@jedsmallwood
Copy link
Author

Thanks for looking into this, you are correct though in that the first worker does in fact bind to the udp port.

@ghost ghost assigned bnoordhuis Nov 26, 2011
@bnoordhuis
Copy link
Member

Confirmed. Will fix.

@DiogoNeves
Copy link

Weird thing, I've confirmed I only get one worker binded (all others) but I don't get the 'on error' call... am I forgetting to activate something? Any ideas?
Thanks

@DiogoNeves
Copy link

Ok, at the moment I'm trying to debug UDP handles being sent through the IPC (which throws a 'Bus error 10' message).
If you're interested in the code that causes this, here's a hacky commit I've put together to test this:
DiogoNeves@da8094d

Do you think UDP handles will be supported soon? I'm still trying to figure out how to fix/work around this issue though.
Since we're on this, would be great to support sending function objects as well, but that would be an extra.

I apologise if the previous message doesn't make any sense :) in that case, ignore me and I'll keep debugging and will come back with more information later.

@AndreasMadsen
Copy link
Member

@DiogoNeves I will first have time to look intro this myself in the upcoming week.

But with just a quick look at your patch I will assume child_process.fork().send do not support handlers they way you create them (perhaps it do not support any UDP handler) and that is why you get Bus error 10.
I belive @bnoordhuis can confirm or disconfirm that.

If you want to continue the work I suggest you step out of the cluster for now and try making it work with child_process.fork() first, that will make your debugging easier.

@bnoordhuis
Copy link
Member

@AndreasMadsen, @DiogoNeves: That's correct. See StreamWrap::Write in src/stream_wrap.cc. It only supports handles that are a sub-class of uv_stream_t types right now, which uv_udp_t is not.

@DiogoNeves: Sorry, I may have underestimated the difficulty of this change. :-/

@DiogoNeves
Copy link

@AndreasMadsen, @bnoordhuis Thanks! :)
@bnoordhuis no problem. Just to make it clear, I don't mind to keep looking at it and adding UDP support in both places (libuv and cluster). It's only a question of you being confortable with me looking, and possibly changing, this on my first patch ever ;) Obviously it would always need a lot of review etc.

I'm really having a lot of fun and learning a lot with all this. I will keep looking at different issues, even if it gets to temporary dead ends. I'm sure I'll submit a good patch at some point hehe :)

@bnoordhuis Would you rather prefer if I look at something else?

@bnoordhuis
Copy link
Member

@DiogoNeves: By all means keep at it if you want. You should probably come hang out in #libuv because the changes to libuv would need to be discussed.

@DiogoNeves
Copy link

Ok, I'll keep investigating :) I've been quite slow this week, sorry.
As soon as I know more about possible changes to the libuv, I'll explain my findings and go from there. I want start changing libuv before discussing it.
I'm already in the channel just in case.
Thanks

@starlogik
Copy link

hi

is there an ETA on fix for clustering UDP socket?

thank you

@starlogi
Copy link

is there any planned (soon) fix for this UDP clustering? without shared access to same socket node as a UDP server becomes severely limited as cannot scale.

thanks

@bnoordhuis
Copy link
Member

is there any planned (soon) fix for this UDP clustering?

Not really. It's one of those nice-to-haves that fully depend on someone having time and the inclination to fix it.

@starlogi
Copy link

Ben

Thanks for prompt response ...

However surely its way more than a "nice to have" as without it nodejs is
severely stilted as a UDP server. We are building a SIP server and if
workers cannot share a socket we cannot cluster SIP processing since the
SIP dialog needs to happen over a single socket (eg: port 5060)

Can we put a bounty on getting this done?

What would a reasonable fee and timeframe look like?

On Sun, Dec 16, 2012 at 2:38 AM, Ben Noordhuis notifications@github.comwrote:

is there any planned (soon) fix for this UDP clustering?

Not really. It's one of those nice-to-haves that fully depend on someone
having time and the inclination to fix it.


Reply to this email directly or view it on GitHubhttps://github.com//issues/2194#issuecomment-11416352.

@bnoordhuis
Copy link
Member

Can we put a bounty on getting this done? What would a reasonable fee and timeframe look like?

It's about two days of work, give or take. As to fees, I should probably get you in touch with the right people. Do you have an email address you can be contacted at?

@starlogi
Copy link

Ben

Then can we progress it ASAP.
ari@starlogik.com

Graci.

On Sun, Dec 16, 2012 at 3:05 AM, Ben Noordhuis notifications@github.comwrote:

Can we put a bounty on getting this done? What would a reasonable fee and
timeframe look like?

It's about two days of work, give or take. As to fees, I should probably
get you in touch with the right people. Do you have an email address you
can be contacted at?


Reply to this email directly or view it on GitHubhttps://github.com//issues/2194#issuecomment-11416533.

@bnoordhuis
Copy link
Member

Thanks, I'll make sure someone gets back to you.

@geggleto
Copy link

Hmm, is this still an active problem? The test code seems to work fine under 0.8.18 and Windows 7 64bit.
$node -v
v0.8.18
$node test.js
12 Apr 01:03:08 - starting udp server on port 1190
12 Apr 01:03:08 - starting udp server on port 1190

Also confirmed its absence in 0.10.0 on centos.

node -v

v0.10.0

node test.js

12 Apr 09:04:43 - starting udp server on port 1190
12 Apr 09:04:43 - starting udp server on port 1190

Maybe someone can confirm that the problem is related to OSX only? Or if its been fixed.

Cheers

@bnoordhuis
Copy link
Member

UDP cluster support was added in 5e7e51c, I just forgot to close this issue.

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

No branches or pull requests

6 participants