Note · evergreen
An MQTT client that reconnects is not a client that resubscribes
- Stage
- evergreen
- Links
- 1 out, 1 in
rumqttc, the Rust MQTT client, reconnects on its own when the broker goes away. It does not resubscribe. A program that subscribes once at startup keeps publishing after a broker restart and never receives another message. In Linux companion agent that meant sensors kept updating while every command from Home Assistant was silently lost.
The fix is to hang the whole session off the broker’s ConnAck. Each time one arrives, the agent subscribes, announces its entities, publishes its state and marks itself online.
Three related traps from the same work:
A zero-capacity channel can park a subscribe forever. The client’s request channel was created with capacity 0, which makes it a rendezvous: a send completes only when the event loop is ready to receive. Under the wrong ordering the subscribe waited indefinitely, and the agent sat connected and silent. The capacity is now 10.
An empty Mosquitto ACL file denies everything and says nothing. With an acl_file configured but empty, clients connect successfully and every publish and subscribe is dropped. It looks exactly like the first bug.
Announce again when Home Assistant starts. The agent listens on homeassistant/status and re-announces its entities when Home Assistant comes online, after a delay that differs per host so a fleet does not answer at once.
Projects
- Linux companion agent A Home Assistant companion for Linux machines, written in Rust.
Projects
- Linux companion agent A Home Assistant companion for Linux machines, written in Rust.