Skip to content

Bind the receive socket to the catch-all addresses #2

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

Closed
wants to merge 2 commits into from

Conversation

AlCalzone
Copy link
Contributor

First of all, thanks for this library - it seems to be the only one that allows to detect Tradfri gateways on a variety of networks. bonjour and multicast-dns both have flaws in this regard.

When mDNSResponder is running on OSX, binding the receive socket to a specific IP address will throw EADDRINUSE, even if reuseAddr is set to true, as can be seen from this rather long bug hunt: AlCalzone/node-tradfri-client#101

The solution seems to be binding the receive socket to the catch-all addresses 0.0.0.0 (IPv4) and ::%<name> (IPv6) instead.

@bnielsen1965
Copy link
Owner

Windows may have issues with this change. I put together this module to address issues with mDNS on Windows machines with multiple network interfaces...

mafintosh/multicast-dns#41

When I attempted to use the catch-all address 0.0.0.0 Windows would select the first interface to listen and as a result would not receive mDNS answers coming back on other interfaces.

However, I did setup a test with your changes on a Windows 10 system and it seems to work okay (perhaps Microsoft fixed this?) but I'm still reluctant to merge due to client systems that could potential fail.

So, a couple of questions for you...

Would it work for you if we added an option that would enable the use of the catch-all 0.0.0.0? This could solve the OSX issue without potentially breaking other implementations.

And have you tried using the module on an OSX system with multiple network interfaces? I don't have access to an OSX system to run tests, I can only test Windows and Linux.

@AlCalzone
Copy link
Contributor Author

Would it work for you if we added an option that would enable the use of the catch-all 0.0.0.0? This could solve the OSX issue without potentially breaking other implementations.

I thought of another solution: Try to bind to a specific IP address, and if that fails due to EADDRINUSE, try again with the catch-all address. Adding an option means the user has to understand what it does, when it should be used and when it shouldn't. The fallback solution means that it just works.

And have you tried using the module on an OSX system with multiple network interfaces? I don't have access to an OSX system to run tests, I can only test Windows and Linux.

I don't have access to OSX either.

@bnielsen1965
Copy link
Owner

I thought of another solution: Try to bind to a specific IP address, and if that fails due to EADDRINUSE, try again with the catch-all address. Adding an option means the user has to understand what it does, when it should be used and when it shouldn't. The fallback solution means that it just works.

Fantastic solution, much better than my proposal. Do you have time to code this or would you like me to take a stab at it?

When I'm in the office I'll check to see if we have a Mac anywhere.

As an alternative, perhaps we can work with Boimb on OSX testing assuming he is game for more work on the same issue. :)

@AlCalzone
Copy link
Contributor Author

I'll see if I can give it a try tomorrow - but no promises.

@Boimb
Copy link

Boimb commented Sep 6, 2018

How I can I help you with this ?
Change the dep in the "node-tradfri-client" to point to "AlCalzone:master" and test ?
Maybe an easier way with just this repo ?

[EDIT] As far as I understood, @AlCalzone included his own version of "mdns-server" in the master Branch of "node-tradfri-client". So I pulled this one for test. Here's the result :

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

Error: addMembership EADDRNOTAVAIL
    at _errnoException (util.js:1022:11)
    at Socket.addMembership (dgram.js:615:11)
    at Socket.iface.socketRecv.dgram.createSocket.once.on.on (/Users/boimb/sandbox/node_modules/@alcalzone/mdns-server/index.js:114:28)
    at emitNone (events.js:106:13)
    at Socket.emit (events.js:208:7)
    at startListening (dgram.js:156:10)
    at _handle.lookup (dgram.js:273:7)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:695:11)

Btw, feel free to ask for further tests.
[/EDIT]

@AlCalzone
Copy link
Contributor Author

@Boimb we basically need someone with OSX to test the changes @bnielsen1965 or I will be making soon. Nothing to do yet, but we'll ping you when there's something to test if you're up to.

@bnielsen1965
Copy link
Owner

bnielsen1965 commented Sep 6, 2018

EDIT: I have a Mac now, the hotfix branch fails, but I may have a fix...

@Boimb can you try the hotfix branch currently in the repo?

https://github.com/bnielsen1965/mdns-server/tree/hotfix

It will retry the catch-all address if the bind fails on the interface address as suggested by @AlCalzone .

@bnielsen1965
Copy link
Owner

Okay, lets try this again...

@Boimb @AlCalzone
I have a hotfix branch and it appears to be working on OSX, Windows, and linux.
If you have time test it out and see if you run into any issues.

@AlCalzone
Copy link
Contributor Author

I'll check tonight

@AlCalzone
Copy link
Contributor Author

AlCalzone commented Sep 7, 2018

The hotfix works for me :) Windows 10

@Boimb
Copy link

Boimb commented Sep 7, 2018

@AlCalzone do you have a branch including this hotfix on "node-tradfri-client" that I can can pull ?

@bnielsen1965
Copy link
Owner

@Boimb If you want to do a quick and dirty test you could download the index.js file from the hotfix branch and copy it into your node_modules/@alcalzone/mdns-server/ directory.

https://github.com/bnielsen1965/mdns-server/blob/hotfix/index.js
Use the Raw link and save as.

@Boimb
Copy link

Boimb commented Sep 7, 2018

I love when it's dirty ^^
Done... and it worked like a charm 👍
Great job !

@AlCalzone
Copy link
Contributor Author

Great. let me know when that is published and I‘ll release a new version 😁

@bnielsen1965
Copy link
Owner

Merged and published as version 1.0.6

@bnielsen1965
Copy link
Owner

@AlCalzone @Boimb Looks like we are in good shape so I'm going to close this. Thanks for helping me improve this module.

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

Successfully merging this pull request may close these issues.

3 participants