mosquitto icon indicating copy to clipboard operation
mosquitto copied to clipboard

If CONNACK packet's state code is non-zero,loop will not stop and try to reconnect many a time

Open wbl-dev opened this issue 9 years ago • 2 comments

Today i want to test password is wrong this case and find that client always try to reconnect. In read_handle_client.c

switch(result){
		case 0:
			mosq->state = mosq_cs_connected;
			return MOSQ_ERR_SUCCESS;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
			return MOSQ_ERR_CONN_REFUSED;
		default:
			return MOSQ_ERR_PROTOCOL;
	}

If result is non-zero we don't modify mosq->state. In mosquitto_loop_forever mosquitto will call mosquitto_reconnect many a time to reconnect.

Should we modify mosq->state if CONNECT fail?

wbl-dev avatar Aug 15 '17 06:08 wbl-dev

What version do you have this issue?

imZack avatar Aug 15 '17 15:08 imZack

In Last version mosquitto_loop_forever will check mosquitto_loop return value. The loop will quit if error is fatal. But MOSQ_ERR_CONN_REFUSED is not deemed to a fatal error, loop will continue and reconnect again.

What i want to ask is should client stop reconnect server and quit loop if CONNECT fail.

Thanks advance :)

wbl-dev avatar Aug 16 '17 03:08 wbl-dev