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

Async API never yields which causes the thread to eat CPU. #1550

Closed
nihilus opened this issue Jan 2, 2020 · 6 comments
Closed

Async API never yields which causes the thread to eat CPU. #1550

nihilus opened this issue Jan 2, 2020 · 6 comments

Comments

@nihilus
Copy link

@nihilus nihilus commented Jan 2, 2020

The async API never yields which causes the thread to eat lots of CPU (about 99%). Adding usleep(10); to mosquitto_loop_misc() fixes this. However I am unsure if that is appropriate.

@karlp

This comment has been minimized.

Copy link
Contributor

@karlp karlp commented Jan 2, 2020

could you share a snippet of how you're using the apis?

@nihilus

This comment has been minimized.

Copy link
Author

@nihilus nihilus commented Jan 2, 2020

	mosq_ret = mosquitto_connect_async(mosq, ipstr, 1883, 0);
	if(mosq_ret != MOSQ_ERR_SUCCESS){
	    fprintf(stderr, "Unable to connect (%s)!\n", mosquitto_strerror(mosq_ret));
       	    goto exit;
        }

	mosq_ret = mosquitto_loop_start(mosq);
	if(mosq_ret != MOSQ_ERR_SUCCESS){
	    fprintf(stderr, "Unable to start loop (%s)!\n", mosquitto_strerror(mosq_ret));
       	    goto exit;
        }

	while(run == -1){
		nanosleep(&tv, NULL);
	}
@nihilus

This comment has been minimized.

Copy link
Author

@nihilus nihilus commented Jan 2, 2020

I will check if #1542 solves the issue tomorrow.

@ralight

This comment has been minimized.

Copy link
Contributor

@ralight ralight commented Jan 2, 2020

mosq_ret = mosquitto_connect_async(mosq, ipstr, 1883, 0);

You've set the keepalive parameter to 0 here. This should be rejected as an invalid value, but it isn't. I would suggest using a value of 10 as the absolute minimum value.

@nihilus

This comment has been minimized.

Copy link
Author

@nihilus nihilus commented Jan 2, 2020

Ah, explains.

@nihilus

This comment has been minimized.

Copy link
Author

@nihilus nihilus commented Jan 3, 2020

@ralight FWIW: Your suggestion worked perfectly. So the bug is that it doesn't validate the argument then.

@ralight ralight closed this in 8f1c8cb Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.