-
Notifications
You must be signed in to change notification settings - Fork 69
Description
Describe the bug
tedge mqtt sub does not timeout when trying to subscribe to the broker that is currently unavailable.
$ TEDGE_MQTT_CLIENT_HOST=foo tedge mqtt sub '#' --duration 1s
2025-10-21T08:23:48.957289Z ERROR MQTT: Failed to connect to broker at 'foo:2883': I/O: failed to lookup address information: nodename nor servname provided, or not known
2025-10-21T08:23:49.961252Z ERROR MQTT: Failed to connect to broker at 'foo:2883': I/O: failed to lookup address information: nodename nor servname provided, or not known
2025-10-21T08:23:50.967627Z ERROR MQTT: Failed to connect to broker at 'foo:2883': I/O: failed to lookup address information: nodename nor servname provided, or not known
2025-10-21T08:23:51.974332Z ERROR MQTT: Failed to connect to broker at 'foo:2883': I/O: failed to lookup address information: nodename nor servname provided, or not knownSimilar behaviour occurs when using tedge mqtt pub:
$ TEDGE_MQTT_CLIENT_HOST=foo tedge mqtt pub test message
2025-10-21T08:22:37.939864Z ERROR MQTT: Failed to connect to broker at 'foo:1883': I/O: failed to lookup address information: nodename nor servname provided, or not known
2025-10-21T08:22:38.942901Z ERROR MQTT: Failed to connect to broker at 'foo:1883': I/O: failed to lookup address information: nodename nor servname provided, or not known
2025-10-21T08:22:39.947183Z ERROR MQTT: Failed to connect to broker at 'foo:1883': I/O: failed to lookup address information: nodename nor servname provided, or not known
2025-10-21T08:22:40.954063Z ERROR MQTT: Failed to connect to broker at 'foo:1883': I/O: failed to lookup address information: nodename nor servname provided, or not knownThe fact that the command's don't timeout causes the tedge diag collect command to assert its 60s timeout per plugin which adds unnecessary time to the collection of the diagnostic information for instances where the MQTT broker is not running.
tedge diag collectTo Reproduce
The behaviour can be reproduced be setting the mqtt client host to a dummy address.
# mqtt sub
TEDGE_MQTT_CLIENT_HOST=foo tedge mqtt sub '#' --duration 1s
# mqtt pub
TEDGE_MQTT_CLIENT_HOST=foo tedge mqtt pub test messageExpected behavior
The tedge mqtt sub and tedge mqtt pub should support a --connection-timeout <duration> flag where the command gives up after a specified timeout. Below shows an example of the flag in use.
tedge mqtt sub '#' --connection-timeout 15s
tedge mqtt pub test message --connection-timeout 15s- With a default connection timeout set to
10s(note the a human friendly duration, instead of assuming a time unit like seconds). - A connection timeout of "0" (e.g. "0s", "0ms" etc.) should be considered as no timeout (resulting infinite connection retries)
Screenshots
Environment (please complete the following information):
- OS [incl. version]:
any - Hardware [incl. revision]:
any - System-Architecture [e.g. result of "uname -a"]:
any - thin-edge.io version [e.g. 0.1.0]:
tedge 1.6.2~243+g61154cd
Additional context