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 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
Copy link
Contributor

karlp commented Jan 2, 2020

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

@nihilus
Copy link
Author

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
Copy link
Author

nihilus commented Jan 2, 2020

I will check if #1542 solves the issue tomorrow.

@ralight
Copy link
Contributor

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
Copy link
Author

nihilus commented Jan 2, 2020

Ah, explains.

@nihilus
Copy link
Author

nihilus commented Jan 3, 2020

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

@lock lock bot locked as resolved and limited conversation to collaborators Jun 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants