Skip to content
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_loop_stop() returns too late #1555

Open
ii7017 opened this issue Jan 8, 2020 · 0 comments
Open

mosquitto_loop_stop() returns too late #1555

ii7017 opened this issue Jan 8, 2020 · 0 comments

Comments

@ii7017
Copy link

ii7017 commented Jan 8, 2020

A) Precondition:
Successfully connect from mosquitto to a broker and stop the broker service from the server.
Register a disconnectCallback like "mosquitto_disconnect_callback_set(mosq, disconnectCallback)"

B) Reproduction:
When getting informed about "unexpected disconnect" by disconnectCallback call:

  1. mosquitto_disconnect(mosq);
  2. mosquitto_loop_stop(mosq, false);

Internally mosquitto_loop_stop() does not return before the reconnect_delay expired (which could be a huge time) and is unnecessary to wait.

C) Possible fix in loop.c:
in mosquitto_loop_forever() use from Line 268:

			// Regularly check state and stop waiting when disconnecting.
			while (reconnect_delay) {
				// Sleep for one second

#ifdef WIN32
Sleep(1000);
#else
req.tv_sec = 1;
req.tv_nsec = 0;
while(nanosleep(&req, &rem) == -1 && errno == EINTR){
req = rem;
}
#endif
reconnect_delay--;

				// Stop waiting in case of disconnecting.
				pthread_mutex_lock(&mosq->state_mutex);
				if (mosq->state == mosq_cs_disconnecting) {
					reconnect_delay = 0;
				}
				pthread_mutex_unlock(&mosq->state_mutex);
			}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant