Skip to content

Commit

Permalink
Fix reconnect delay backoff behaviour.
Browse files Browse the repository at this point in the history
Closes #1027. Thanks to Harm Verhagen.

Bug: #1027
  • Loading branch information
ralight committed Dec 4, 2018
1 parent e169f1c commit 5d02f58
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Broker:
because this can lead to confusing "Protocol not supported" errors if the
network is down. Closes #1062.

Library:
- Fix reconnect delay backoff behaviour. Closes #1027.

Client:
- Always print leading zeros in mosquitto_sub when output format is hex.
Closes #1066.
Expand Down
8 changes: 6 additions & 2 deletions lib/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,12 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
}else{
pthread_mutex_unlock(&mosq->state_mutex);

if(mosq->reconnect_delay > 0 && mosq->reconnect_exponential_backoff){
reconnect_delay = mosq->reconnect_delay*reconnects*reconnects;
if(mosq->reconnect_delay_max > mosq->reconnect_delay){
if(mosq->reconnect_exponential_backoff){
reconnect_delay = mosq->reconnect_delay*(reconnects+1)*(reconnects+1);
}else{
reconnect_delay = mosq->reconnect_delay*(reconnects+1);
}
}else{
reconnect_delay = mosq->reconnect_delay;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ int mosquitto_reconnect_delay_set(struct mosquitto *mosq, unsigned int reconnect
{
if(!mosq) return MOSQ_ERR_INVAL;

if(reconnect_delay == 0) reconnect_delay = 1;

mosq->reconnect_delay = reconnect_delay;
mosq->reconnect_delay_max = reconnect_delay_max;
mosq->reconnect_exponential_backoff = reconnect_exponential_backoff;
Expand Down

0 comments on commit 5d02f58

Please sign in to comment.