fix(web): raise on MQTT connect timeout in _publish_arm_request

Code review on 9f203d8 caught a silent-failure mode: MessageBus.connect
logs and returns without raising when the MQTT handshake times out, so
an overloaded broker would let bus.publish() enqueue into paho's outbox
only to be discarded by the immediate disconnect(). The web endpoint
would return 202 even though the FSM never received the request.

Guard with 'if not bus.connected: raise RuntimeError'. The existing
try/except in arm_system/disarm_system catches the exception and turns
it into a 503 with the same log message as other bus failures.
This commit is contained in:
adlee-was-taken
2026-04-05 12:07:20 -04:00
parent 7b33cb7bb4
commit 12821648ca

View File

@@ -61,6 +61,8 @@ def _publish_arm_request(cfg: VigilarConfig, payload: dict) -> None:
bus = MessageBus(cfg.mqtt, client_id="vigilar-web-arm-request") bus = MessageBus(cfg.mqtt, client_id="vigilar-web-arm-request")
bus.connect() bus.connect()
if not bus.connected:
raise RuntimeError("MQTT broker did not accept connection within timeout")
try: try:
bus.publish(Topics.SYSTEM_ARM_REQUEST, payload) bus.publish(Topics.SYSTEM_ARM_REQUEST, payload)
finally: finally: