-
Notifications
You must be signed in to change notification settings - Fork 65
Description
Describe the bug
Maybe it's not a bug per se, but while working on MQTT client authentication, when the broker refuses the connection, the tedge mqtt sub tedge/measurements
command does not exit, but keeps attempting to connect and outputting ERROR: Connection refused, return code: NotAuthorized
without exiting. This is different from the case when the broker is not even running, and the process exits with the following message:
Error: failed to subscribe the topic "tedge/measurements" with QoS "AtMostOnce".
Caused by:
MQTT connection error: I/O: Connection refused (os error 111)
Hint: Is MQTT server running?
The process also correctly exits with a failure when we attempt to publish a message instead of subscribing.
To Reproduce
- In
/etc/tedge/mosquitto-conf/tedge-mosquitto.conf
, changeallow_anonymous
to false sudo systemctl restart mosquitto
tedge mqtt sub tedge/measurements
- The command should print the
NotAuthorized
error message every 1s.
Expected behavior
I think this behaviour should be made more consistent and the process should exit first time it receives NotAuthorized
message from the broker, as it is unlikely that retrying would help, and so that the command can properly report the failure if it's being called e.g. from a script. There are probably other possible errors where we should just exit and report the failure to the users, and perhaps others where exiting would be unwise, and some other strategy, like exponential backoff, should be used. While fixing the behaviour for NotAuthorized
case, we could consider these other cases as well.