-
-
Notifications
You must be signed in to change notification settings - Fork 31
Error: bind EADDRINUSE #101
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
Comments
You probably have another mDNS client running, which listens on port 5353. I’m not sure if it’s possible to share that port. |
Thx for quick reply.
I get
Can't find the process to kill :/ |
Which OS are you using? |
MacOS 10.12 I found that :
|
Everything works fine if I downgrade to 1.2.1. |
Ok then it definitely has to do with the package used for mDNS discovery. I previously used bonjour which is a bit buggy on my network. I'll have to see what is different in the socket creation. |
I just tried the above on my Windows machine where mDNSResponder was also running. The error handling was not correct, so an error during discovery lead to an unhandled exception instead of a promise rejection. Nonetheless, I only get that error when explicitly setting |
The only difference I could spot between the two modules are IPv6 support. Whenever I use both, I notice that the const mdns = createMDNSServer({
reuseAddr: true,
interfaces: ["your.ipv4.address.here"],
loopback: false,
}); |
Thanks for investigating so fast ! |
Well, I tried, since I could try not to find a gateway but not getting the same err...
Ofc, 10.0.10.194 is my ip. // /build/lib/discovery.js
function discoverGateway(timeout = 10000) {
const mdns = createMDNSServer({
reuseAddr: true,
interfaces: ["10.0.10.194"],
loopback: false,
}); [edit] Same result when back home. Will stick to 1.2.1 4now ;)[/edit] |
If you're willing to try a bit more, I have something for you. Put the following code in a standalone js file and run it with the node CLI. const dgram = require("dgram");
const os = require("os");
const all = os.networkInterfaces();
const addresses = Object.keys(all)
.map(key => all[key])
.reduce((acc, arr) => acc.concat(arr), [])
.filter(inf => inf.family === 'IPv4' && !inf.internal)
.map(inf => inf.address)
;
let sock1, sock2;
try {
sock1 = dgram.createSocket({type: "udp4", reuseAddr: true});
sock1.bind(5353, addresses[0]);
sock1.close();
console.log("binding with reuseAddr works");
} catch (e) {
console.error("binding with reuseAddr didn't work");
}
try {
sock2 = dgram.createSocket({type: "udp4", reuseAddr: false});
sock1.bind(5353, addresses[0]);
sock2.close();
console.log("binding without reuseAddr works");
} catch (e) {
console.error("binding without reuseAddr didn't work");
} For me it prints
|
Ofc I want :D I get
|
Ok now I'm confused... Maybe there's a bug in console.dir(iface);
console.dir(mDNS.config); and try your original sandbox code? |
Here you go:
|
To get rid of the However I still don't get why the error appears despite of Once I've figured this out, I'll try to find a way where errors for single interfaces don't break the entire discovery process. |
I stumbled over this bug aswell. problem is that in the discovery function theres a unhandled error event:
|
AH! master contains the code |
However that does not completely fix the discovery. The way it currently is, the internal |
Don't know if it's the right way, but I changed may package.json like this :
Then :
Now:
Seems the process is in "standby" as i have to kill it by Ctrl+c. |
True, and I remember it worked fine on OSX. So I quickly tested:
so that looks like a regression |
As I wrote earlier, this came from changing the library used for mDNS discovery. The old one didn't use IPv6, the new one does. The weird thing is, binding the sockets on Windows works just fine.
That should work. Can you please run the script from #101 (comment) (with |
Sure, here's the output (IPv4)
debug (IPv4):
debug (IPv6):
|
I don't see any change. |
(╯°□°)╯︵ ┻━┻ Ok next try, put this in a sandbox file and run it please (update the IP addresses if they changed): const dgram = require("dgram");
const ipv6Addr = "fe80::433:987d:5e93:80ab";
const ipv6Suffix = "en0";
const ipv4Addr = "10.0.10.194";
const combinations = [
{ type: "udp4", addr: ipv4Addr, reuseAddr: true },
{ type: "udp6", addr: ipv6Addr, reuseAddr: true },
{ type: "udp6", addr: `${ipv6Addr}%${ipv6Suffix}`, reuseAddr: true },
{ type: "udp4", addr: ipv4Addr, reuseAddr: false },
{ type: "udp6", addr: ipv6Addr, reuseAddr: false },
{ type: "udp6", addr: `${ipv6Addr}%${ipv6Suffix}`, reuseAddr: false },
];
function doit(i) {
return new Promise((resolve) => {
const { type, addr, reuseAddr } = combinations[i];
let success = false;
const sock = dgram.createSocket({ type, reuseAddr });
sock.on("error", (e) => {
success = false;
console.error(e);
});
try {
sock.bind(5353, addr);
success = true;
} catch (e) { console.error(e) }
setTimeout(() => {
sock.close();
console.log(`binding to ${addr} with reuseAddr=${reuseAddr} ${success ? "works" : "didn't work"}`);
resolve();
}, 100);
});
}
doit(0)
.then(() => doit(1))
.then(() => doit(2))
.then(() => doit(3))
.then(() => doit(4))
.then(() => doit(5))
; For me, everything with reuseAddr works, and the rest doesn't. |
Arf...
|
Ok now I'm genuinely confused... What about const ipv4Addr = "0.0.0.0";
const ipv6Addr = "::"; ? |
Ok I have two more tests for you. You need to install IPv4var mdns = require('multicast-dns')(/*opts*/);
mdns.on('response', function (response) {
console.log('got a response packet:', response)
})
mdns.on('query', function (query) {
console.log('got a query packet:', query)
})
const domain = "_coap._udp.local";
mdns.on("ready", () => {
mdns.query([
{ name: domain, type: "A" },
]);
}); IPv6var opts = {
interface: '::%en0',
type: 'udp6',
ip: 'ff02::1:3'
}
var mdns = require('multicast-dns')(opts);
mdns.on('response', function (response) {
console.log('got a response packet:', response)
})
mdns.on('query', function (query) {
console.log('got a query packet:', query)
})
const domain = "_coap._udp.local";
mdns.on("ready", () => {
mdns.query([
{ name: domain, type: "A" },
]);
}); If it works, you get a response packet written to the console ( |
Really appreciate your tenacity :D
Seems really better 👍 |
No response packet, but - hey - no error either. I'll create a branch where I use that package for discovery and let you know when there's something to test. |
the ipv4 example seems to work:
the ipv6 example did not output anything. some input:
running osx (Darwin Kernel Version 17.5.0) |
Whats the name of your network interface? If its not |
its en0 as well (wifi nic on osx), but i also try to remove that suffix without any change |
Tried current #master branch
I checked that the reuse flag is already set. I added some debug output in the mdns-server: here is a log output what happens on my osx machine when i start the tradfri discovery:
fyi, here's the modified part of the mdns-server:
The same also for |
I took a look how bonjour dies this, https://github.com/mafintosh/multicast-dns/blob/master/index.js
Side question: any particular reasons why use mdns-server over bonjour? |
Selfishness, bonjour does not work on my own network ;) |
Some more info for you guys as you are waiting: |
Personally, I’m really happy with 1.2. For sure it’d be great to be able to get latest, but it’s not blocking me for now. “Take your time” ;) |
Coincidentally, I did have some spare time. Most of the work was already done, I just had to extend it to multiple interfaces. If you like, you can test the version from #103 |
btw Selfishness is always a VERY good reason ;) |
You really rock dude! |
Glad it works for you. Now it doesn't work for me :D |
Okay, short update. I seem to be able to detect the gateway now that I'm back |
This works for me too 👍 |
This will be released in v1.3.3 shortly. Thanks for the help! |
The original creator of |
currently not much time from my side, would a |
We just need someone to test if things still work with the alternative changes. If you don't have time, no problem. |
Hi,
Just wanted to try the lib in a sandbox file :
then when I :
I get this message :
Ofc, I tried
But no other node process running ...
Any clue ?
Thx for help.
The text was updated successfully, but these errors were encountered: