Fix reconnect backoff where connections are dropped

Closes #737. Thanks to chelliwell.
pull/1600/head
Roger A. Light 6 years ago
parent 982758a76e
commit cf7ac452b8

@ -5,6 +5,10 @@ Broker:
- Fix slow websockets performance when sending large messages. Closes #1390.
- Fix bridges potentially not connecting on Windows. Closes #478.
Client library:
- Fix reconnect backoff for the situation where connections are dropped rather
than refused. Closes #737.
Documentation:
- Improve details on global/per listener options in the mosquitto.conf man page.
Closes #274.

@ -31,6 +31,9 @@ Contributors:
static void connack_callback(struct mosquitto *mosq, uint8_t reason_code, uint8_t connect_flags, const mosquitto_property *properties)
{
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received CONNACK (%d)", mosq->id, reason_code);
if(reason_code == MQTT_RC_SUCCESS){
mosq->reconnects = 0;
}
pthread_mutex_lock(&mosq->callback_mutex);
if(mosq->on_connect){
mosq->in_callback = true;

@ -194,7 +194,6 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
{
int run = 1;
int rc;
unsigned int reconnects = 0;
unsigned long reconnect_delay;
#ifndef WIN32
struct timespec req, rem;
@ -202,6 +201,8 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
if(!mosq) return MOSQ_ERR_INVAL;
mosq->reconnects = 0;
if(mosq->state == mosq_cs_connect_async){
mosquitto_reconnect(mosq);
}
@ -209,9 +210,6 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
while(run){
do{
rc = mosquitto_loop(mosq, timeout, max_packets);
if (reconnects !=0 && rc == MOSQ_ERR_SUCCESS){
reconnects = 0;
}
}while(run && rc == MOSQ_ERR_SUCCESS);
/* Quit after fatal errors. */
switch(rc){
@ -245,9 +243,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
if(mosq->reconnect_delay_max > mosq->reconnect_delay){
if(mosq->reconnect_exponential_backoff){
reconnect_delay = mosq->reconnect_delay*(reconnects+1)*(reconnects+1);
reconnect_delay = mosq->reconnect_delay*(mosq->reconnects+1)*(mosq->reconnects+1);
}else{
reconnect_delay = mosq->reconnect_delay*(reconnects+1);
reconnect_delay = mosq->reconnect_delay*(mosq->reconnects+1);
}
}else{
reconnect_delay = mosq->reconnect_delay;
@ -256,7 +254,7 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)
if(reconnect_delay > mosq->reconnect_delay_max){
reconnect_delay = mosq->reconnect_delay_max;
}else{
reconnects++;
mosq->reconnects++;
}
#ifdef WIN32

@ -326,6 +326,7 @@ struct mosquitto {
char *host;
int port;
char *bind_address;
unsigned int reconnects;
unsigned int reconnect_delay;
unsigned int reconnect_delay_max;
bool reconnect_exponential_backoff;

Loading…
Cancel
Save