New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mosquitto_reconnect_delay_set() not delaying reconnect attemtps #1027

Closed
harmv opened this Issue Nov 9, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@harmv
Copy link

harmv commented Nov 9, 2018

I'm using mosquitto_reconnect_delay_set() but it does not seem to work as advertised.
Both with exponential backof true and false it does not work, I see no backoff at all.

steps to reproduce

Before connecting I set:
int ret = mosquitto_reconnect_delay_set(mqtt_instance.m, 3, 60, true);

I connect to an mqtt server which is up, but intentionally with incorrect credentials, so the connection fails with on_connect callback result = 5.

I run mosquitto with mosquitto_loop_forever()

expected behavior

The reconnection attempts should be slower and slower.
if exponential is true: 0s, 3s, 12s, 48s, 60s
if exponential is false: 0s, 3s, 6s, 9s, 12s, 15s, etc..

actual behaviour

I see reconnection attempts happen every 6-7s, and that time does not increase. not when exponential is true, nor when false.

See logging, connection attemps are evenly spaced in time.

Client MyPythonHarm sending CONNECT
Client MyPythonHarm received CONNACK (5)
2018-11-09T14:09:07.038Z:iot.c:125:on_connect 5
2018-11-09T14:09:07.038Z:iot.c:139:on_disconnect res 5
Client MyPythonHarm sending CONNECT
Client MyPythonHarm received CONNACK (5)
2018-11-09T14:09:14.659Z:iot.c:125:on_connect 5
2018-11-09T14:09:14.660Z:iot.c:139:on_disconnect res 5
Client MyPythonHarm sending CONNECT
Client MyPythonHarm received CONNACK (5)
2018-11-09T14:09:22.270Z:iot.c:125:on_connect 5
2018-11-09T14:09:22.271Z:iot.c:139:on_disconnect res 5

version

ii libmosquitto-dev:amd64 1.5.3-0mosquitto1~xenial

On ubuntu 16.04 LTS.

notes

When looking at the source code (lib/loop.c) It seems obvious that the case where reconnect_exponential_backoff is false does not work. Nowhere in the code path is reconnect_delay increased, ever.

For the case when reconnect_exponential_backoff is true, its not clear to me why it doesn't work. It seems that somehow reconnects gets reset to 0 after every connection attempt.

Note that in my case the TCP connection to the mqtt server succeeds, the connection fails due to an code 5 (incorrect credentials (intentional))

@ralight

This comment has been minimized.

Copy link
Contributor

ralight commented Nov 9, 2018

Thanks for the report, it looks like you're right.

@ralight ralight added this to the 1.5.5 milestone Nov 9, 2018

ralight added a commit that referenced this issue Dec 4, 2018

Fix reconnect delay backoff behaviour.
Closes #1027. Thanks to Harm Verhagen.

Bug: #1027
@ralight

This comment has been minimized.

Copy link
Contributor

ralight commented Dec 4, 2018

This is now fixed on the fixes branch.

@ralight ralight closed this Dec 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment