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

Homebridge listens on tcp6 only #1277

Closed
dkrizic opened this issue May 5, 2017 · 6 comments

Comments

Projects
None yet
6 participants
@dkrizic
Copy link

commented May 5, 2017

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?

@cybermerlo

This comment has been minimized.

Copy link

commented May 7, 2017

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.

@fuzzy01

This comment has been minimized.

Copy link

commented Jul 14, 2017

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

nodejs/node#9390
and here
nodejs/node@12cf359

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');

@stale

This comment has been minimized.

Copy link

commented Jan 10, 2018

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.

@stale stale bot added the stale label Jan 10, 2018

@stale stale bot closed this Jan 24, 2018

@RobotLimeLtd

This comment has been minimized.

Copy link

commented May 5, 2018

fuzzy01's fix worked for me - thanks!

@Sailing74

This comment has been minimized.

Copy link

commented Sep 24, 2018

It just worked for me as well - thanks!

Any plans to include this into homebridge in some way?

@mrvnklm

This comment has been minimized.

Copy link

commented Jun 21, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.