Homebridge: Homebridge listens on tcp6 only

Created on 6 May 2017  Â·  6Comments  Â·  Source: homebridge/homebridge

Hi,

I have two HomeBridge instances running. The problematic one is on Debian:

root@supermicro:/etc# netstat -an | grep 51828 | grep LISTEN
tcp6       0      0 :::51828                :::*                    LISTEN     

It listens on IPv6 only, but is advertised with IPv4 and IPv6:

root@supermicro:/etc# avahi-browse --verbose _hap._tcp | grep Supermicro
Server version: avahi 0.6.31; Host name: Supermicro.local
E Ifce Prot Name                                          Type                 Domain
+   eth1 IPv6 Homebridge Supermicro                         _hap._tcp            local
+   eth1 IPv4 Homebridge Supermicro                         _hap._tcp            local
+   eth0 IPv6 Homebridge Supermicro                         _hap._tcp            local
+   eth0 IPv4 Homebridge Supermicro                         _hap._tcp            local

Another instance on a Mac works fine:

➜  ~ netstat -an | grep 51826  
tcp46      0      0  *.51826                *.*                    LISTEN     

This one listens on both, IPv4 and IPv6 and is advertised as such.

How can I force hombridge to use both, IPv4 and IPv6 or advertise IPv6 only?

stale

Most helpful comment

This the result of the way nodejs creates the server socket, see here:
(homebridge / hap-nodejs creates the server socket without specifying a hostname)

https://github.com/nodejs/node/issues/9390
and here
https://github.com/nodejs/node/commit/12cf3594235e6c4c6838ae7588b5e73ad9775dfa

It looks like the behaviour of nodejs on Ubuntu/Debian has changed, it opens only a tcp6 socket.

It is easy to test it, if you start a simple server:

node -e "net.createServer(c=>console.log).listen(5555)"

netstat -a | grep 5555
tcp6       0      0 [::]:5555               [::]:*                  LISTEN    

The solution is to modify hap-nodejs to create a tcp4 server socket or both.

A quick fix is to modify eventedhttp.js in /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util, in line 60:

this._tcpServer.listen(targetPort);

to this

this._tcpServer.listen(targetPort, '0.0.0.0');

All 6 comments

same issue here (raspbian - rasp b+).

This problem has been already discussed before, but, usually they solved it by reinstalling a fresh version of homebridge or disabling tcp6. Both solution doesn't work for me.
As dkrizic pointed out only the tcp6 port get opened by homebridge not the tcp4.

Bonjour browser detect Homebridge at x.x.x.x:51824 and also homekit find the accessory, but pairing always fail.

This the result of the way nodejs creates the server socket, see here:
(homebridge / hap-nodejs creates the server socket without specifying a hostname)

https://github.com/nodejs/node/issues/9390
and here
https://github.com/nodejs/node/commit/12cf3594235e6c4c6838ae7588b5e73ad9775dfa

It looks like the behaviour of nodejs on Ubuntu/Debian has changed, it opens only a tcp6 socket.

It is easy to test it, if you start a simple server:

node -e "net.createServer(c=>console.log).listen(5555)"

netstat -a | grep 5555
tcp6       0      0 [::]:5555               [::]:*                  LISTEN    

The solution is to modify hap-nodejs to create a tcp4 server socket or both.

A quick fix is to modify eventedhttp.js in /usr/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util, in line 60:

this._tcpServer.listen(targetPort);

to this

this._tcpServer.listen(targetPort, '0.0.0.0');

This issue has been automatically marked as stale because it has not had recent activity, and will be closed if no further activity occurs. If this issue was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.

fuzzy01's fix worked for me - thanks!

It just worked for me as well - thanks!

Any plans to include this into homebridge in some way?

For everyone running the docker image, adding the following to startup.sh in your shared homebridge folder does the trick, even when the container is rebuilt:
sed -i.bak "s/this._tcpServer.listen(targetPort);/this._tcpServer.listen(targetPort, '0.0.0.0');/" /usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/eventedhttp.js

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tokeraabjerg picture tokeraabjerg  Â·  3Comments

INFINIX98 picture INFINIX98  Â·  5Comments

JangoBritt picture JangoBritt  Â·  3Comments

Ludelag picture Ludelag  Â·  4Comments

350d picture 350d  Â·  6Comments