Map port conflict on start error into a known error#6445
Conversation
|
To answer some likely questions in advance:
It's the only plugin that does not run on host and binds to a port. Its incredibly unlikely to ever run into this issue in truth since observer is always started first and spends very little time down during updates and such. An addon would have to start and steal port 4357 during one of those small windows. But figured I'd handle it for completeness just in case.
Addons which run on the host network can also fail due to port conflict if something else has already bound a port they need. However as mentioned in the description, these addons do not enumerate the ports they use anywhere. The service itself just binds to ports as needed in code. Which means from a docker perspective these containers are fine, they start without issue. This won't present as a docker issue in this case, it will present as an issue with the service itself. Docker won't even know anything is wrong at all unless the container crashes with the service or there is a healthcheck, in which case watchdog will kick in but it won't know why. The only thing the user can do here is check the logs and hopefully the service outputs an intelligible error. Unfortunately this applies to the Home Assistant container as well since it also runs on the host network. Supervisor isn't going to be able to detect and report a port conflict error, Home Assistant core is going to have to do that if we want that behavior. |
Proposed change
Port conflict errors between addons happen fairly frequently. This is when an addon tries to start and bind to the port the user listed in the config and fails because something has already bound that port. This shows up a lot in sentry for a variety of reasons:
The common request here is to handle this with static checking on save of the config. Unfortunately 3 above makes this impossible. Particularly the addons running on host network case as those do not clearly list their ports anywhere, the service can just bind to them as needed in code.
The best we can do is return a known and well-described error to the user that makes it very clear that a port conflict was the issue and what port is the problem.
Type of change
Additional information
Checklist
ruff format supervisor tests)If API endpoints or add-on configuration are added/changed: