Skip to content

go2rtc binds to localhost only while go2rtc client tries to connect to the docker container host IP #130144

Description

@linkages

The problem

After upgrading to homeassistant 2024.11.0, I noticed in my logs a bunch of go2rtc errors.
After reading about the new go2rtc integration I believe the problem is that go2rtc is being started with its api port bound to localhost:11984 instead of the *:11984 or the IP of the machine.

When I run the go2rtc integration with debug_ui set to true it does listen on *:11984

What version of Home Assistant Core has the issue?

core-2024.11.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

go2rtc

Link to integration documentation on our website

https://www.home-assistant.io/integrations/go2rtc/

Diagnostics information

This is what lsof of the go2rtc process looks like when run in debug_ui mode:

[root@ha-1 ~]# lsof -p 291042
COMMAND    PID USER  FD      TYPE   DEVICE SIZE/OFF     NODE NAME
go2rtc  291042 root cwd       DIR    254,2     4096       28 /config
go2rtc  291042 root rtd       DIR     0,57     4096   121208 /
go2rtc  291042 root txt       REG     0,57  5695036   121168 /bin/go2rtc
go2rtc  291042 root   0r      CHR      1,3      0t0       56 /dev/null
go2rtc  291042 root   1w     FIFO     0,15      0t0 15182024 pipe
go2rtc  291042 root   2w     FIFO     0,15      0t0 15182024 pipe
go2rtc  291042 root   3u  a_inode     0,16        0       89 [eventpoll:4,5,6,7,9]
go2rtc  291042 root   4u  a_inode     0,16        0       89 [eventfd:12]
go2rtc  291042 root   5u     IPv4 15182873      0t0      TCP localhost:18554 (LISTEN)
go2rtc  291042 root   6u     IPv6 15182880      0t0      TCP *:18555 (LISTEN)
go2rtc  291042 root   7u     IPv6 15180767      0t0      TCP *:11984 (LISTEN)
go2rtc  291042 root   9u     IPv6 15182032      0t0      TCP localhost:11984->localhost:53988 (ESTABLISHED)

while this is what it looks like with debug_ui turned off:

[root@ha-1 ~]# lsof -p 291681
COMMAND    PID USER  FD      TYPE   DEVICE SIZE/OFF     NODE NAME
go2rtc  291681 root cwd       DIR    254,2     4096       28 /config
go2rtc  291681 root rtd       DIR     0,57     4096   121208 /
go2rtc  291681 root txt       REG     0,57  5695036   121168 /bin/go2rtc
go2rtc  291681 root   0r      CHR      1,3      0t0       56 /dev/null
go2rtc  291681 root   1w     FIFO     0,15      0t0 15184858 pipe
go2rtc  291681 root   2w     FIFO     0,15      0t0 15184858 pipe
go2rtc  291681 root   3u  a_inode     0,16        0       89 [eventpoll:4,5,6,8]
go2rtc  291681 root   4u  a_inode     0,16        0       89 [eventfd:10]
go2rtc  291681 root   5u     IPv4 15183775      0t0      TCP localhost:18554 (LISTEN)
go2rtc  291681 root   6u     IPv6 15183782      0t0      TCP *:18555 (LISTEN)
go2rtc  291681 root   8u     IPv4 15184866      0t0      TCP localhost:11984 (LISTEN)

This is running the latest home assistant container.

Here is my docker-compose.yaml file:

services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /home/eli/src/ha/config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    environment:
      - TZ=EST5EDT
    privileged: true
    network_mode: host

It is running as a privileged container with its network set to host mode.

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Here is a snippet from "docker compose logs" that shows the connection errors

The docker container host IP is 192.168.1.33


homeassistant  | 2024-11-08 11:03:13.539 WARNING (MainThread) [homeassistant.components.go2rtc] Could not start go2rtc server
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1091, in _wrap_create_connection
homeassistant  |     sock = await aiohappyeyeballs.start_connection(
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohappyeyeballs/impl.py", line 104, in start_connection
homeassistant  |     raise first_exception
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohappyeyeballs/impl.py", line 82, in start_connection
homeassistant  |     sock = await _connect_sock(
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohappyeyeballs/impl.py", line 174, in _connect_sock
homeassistant  |     await loop.sock_connect(sock, address)
homeassistant  |   File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 641, in sock_connect
homeassistant  |     return await fut
homeassistant  |            ^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 681, in _sock_connect_cb
homeassistant  |     raise OSError(err, f'Connect call failed {address}')
homeassistant  | ConnectionRefusedError: [Errno 111] Connect call failed ('192.168.1.33', 11984)
homeassistant  |
homeassistant  | The above exception was the direct cause of the following exception:
homeassistant  |
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/go2rtc_client/rest.py", line 55, in request
homeassistant  |     resp = await self._session.request(method, url, **kwargs)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 663, in _request
homeassistant  |     conn = await self._connector.connect(
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 563, in connect
homeassistant  |     proto = await self._create_connection(req, traces, timeout)
homeassistant  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1032, in _create_connection
homeassistant  |     _, proto = await self._create_direct_connection(req, traces, timeout)
homeassistant  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1366, in _create_direct_connection
homeassistant  |     raise last_exc
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1335, in _create_direct_connection
homeassistant  |     transp, proto = await self._wrap_create_connection(
homeassistant  |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/aiohttp/connector.py", line 1106, in _wrap_create_connection
homeassistant  |     raise client_error(req.connection_key, exc) from exc
homeassistant  | aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host localhost:11984 ssl:default [Connect call failed ('192.168.1.33', 11984)]
homeassistant  |
homeassistant  | The above exception was the direct cause of the following exception:
homeassistant  |
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/go2rtc_client/exceptions.py", line 56, in _func
homeassistant  |     return await func(*args, **kwargs)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/go2rtc_client/rest.py", line 74, in get_info
homeassistant  |     resp = await self._client.request("GET", self.PATH)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/go2rtc_client/rest.py", line 58, in request
homeassistant  |     raise ClientError(msg) from err
homeassistant  | aiohttp.client_exceptions.ClientError: Server communication failure: Cannot connect to host localhost:11984 ssl:default [Connect call failed ('192.168.1.33', 11984)]
homeassistant  |
homeassistant  | The above exception was the direct cause of the following exception:
homeassistant  |
homeassistant  | Traceback (most recent call last):
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/go2rtc/__init__.py", line 118, in async_setup
homeassistant  |     await server.start()
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/go2rtc/server.py", line 97, in start
homeassistant  |     await self._start()
homeassistant  |   File "/usr/src/homeassistant/homeassistant/components/go2rtc/server.py", line 136, in _start
homeassistant  |     await client.validate_server_version()
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/go2rtc_client/exceptions.py", line 56, in _func
homeassistant  |     return await func(*args, **kwargs)
homeassistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/go2rtc_client/rest.py", line 150, in validate_server_version
homeassistant  |     application_info = await self.application.get_info()
homeassistant  |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
homeassistant  |   File "/usr/local/lib/python3.12/site-packages/go2rtc_client/exceptions.py", line 66, in _func
homeassistant  |     raise Go2RtcClientError from exc
homeassistant  | go2rtc_client.exceptions.Go2RtcClientError


### Additional information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions