-
Notifications
You must be signed in to change notification settings - Fork 445
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
token->wait() hangs when publishing from 2 threads #499
Comments
I'll have a look and maybe put up new example with two threads publishing. |
That's great. In meantime I have investigated it a bit and it seems that the problem is caused by wrong synchronization of noBufferedMessages member of MQTTAsync on pahoc side. In can happen that two threads can simultaneously accesses the check on this member, both commands are added to the list and increase this number, so in effect in MQTTAsync_add function processing enters condition
where it should never enter for our create options (delete_oldest_messages(false)) and then ListDetach is called which causes removing the first publish command from the processing. So on pahocpp side wait corresponding to the publish never gets released. |
OK. That's what I was afraid of. This should be an issue in the Paho C repo. I will copy and paste the issue there. |
I think this is because of the lack of synchronization in MQTTAsync_send, the conflict arising here:
I've taken a C library trace of the occurrence: and tried out adding a lock/unlock of mqttasync_mutex to MQTTAsync_send, which appears to work for this case. I'll need to check it doesn't affect anything else. |
It looks like the upstream fix has corrected this. |
Hello
Consider the following example
We publish messages in loop from two threads. Publish is synchronous. Almost every time we observe that one of threads hangs on token->wait(), while other is publishing. From time to time we see also error MQTT error [-12]: No more messages can be buffered for some publish. Our observation is that this is related to setting max_buffered_messages to 1 (increasing this number helps).
Is it a bug that max_buffered_messages set to 1 causes hang or we just misconfigured something? If the second case please explain, how to set it (e.g. in relation to number of threads).
The text was updated successfully, but these errors were encountered: