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() hangs on windows #117

Closed
ralight opened this issue Mar 15, 2016 · 2 comments
Closed

mosquitto_loop_stop() hangs on windows #117

ralight opened this issue Mar 15, 2016 · 2 comments

Comments

@ralight
Copy link
Contributor

ralight commented Mar 15, 2016

migrated from Bugzilla #452918
status NEW severity normal in component Mosquitto client library for ---
Reported in version unspecified on platform PC
Assigned to: Roger Light

On 2014-11-23 16:29:33 -0500, Roger Light wrote:

(imported from launchpad)

  1. On many unix-like systems, system call such as read, write is a thread cancellation point specified by posix. But on windows, pthread_win32 implementation, socket family system call is not thread cancellation point, that means if i enable the thread support in mosquitto, there wouldn't be any thread cacellation point in mosquitto_loop_forever. So if calling mosquitto_loop_stop(mosq, true), then the pthread_join() which is called after pthread_cancel() will be blocked as the mosquitto_loop_forever() has not any cancellation point.

a patch to lib/mosquitto.c below to setup a cancellation point manually:

@@ -868,6 +868,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets)

while(run){
do{
+#ifdef WIN32

  • pthread_testcancel();
    +#endif
    rc = mosquitto_loop(mosq, timeout, max_packets);
    if (reconnects !=0 && rc == MOSQ_ERR_SUCCESS){
    reconnects = 0;

  1. Sleep() call on windows is not a cancellation point, too. And it is used in mosquitto_loop_forever() to do backoff in reconnecting phase, it will also prevent mosquitto_loop_stop() from returning immediately. pthread_cond_timewait() may be a better alternative.
SigmundVik added a commit to SigmundVik/mosquitto that referenced this issue Jul 12, 2020
Before this commit, mosquitto_loop_forever() would not always
terminate on Windows when calling mosquitto_loop_stop() with
the force flag set to true.

This commit adds explicit thread cancellation points in
mosquitto_loop_forever() as described in issue eclipse#117 to
ensure that mosquitto_loop_stop() does not hang when
joining the Mosquitto thread.

Closes eclipse#117.

Signed-off-by: Sigmund Vik <[email protected]>
@SigmundVik
Copy link
Contributor

Excellent, thank you for the fix 👍

@ralight
Copy link
Contributor Author

ralight commented Aug 12, 2020

No problem. I just didn't have the time to be happy with your other patch, but I've not forgotten it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants