-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
pubsub library not thread safe. #1055
Comments
I think I have a Similar problem. My Setup: ESP8266
And here is the Serial Print:
Is this a Bug? |
How is payload_d and length_d defined? |
Yes, its getting defined by my callback function:
|
But how/where are they declared? |
Here is your problem, the callback provides you with a buffer (byte* payload) owned by the mqtt library, once you return from the callback, the mqtt will likely free the buffer or re-use it, so once you return that memory space can be used by anyone else. You need to copy the buffer in your callback: And when you later have consumed the content of payload_d, you need to release it: |
The problem is, that I am consuming The payload_d slowly over time |
There is no magic, you cannot use the buffer that pubSub will re-circulate or free once you return from the callback, you need to copy it to a buffer you have allocated/own. |
Your problem is anyway not related to the problem reported in this thread. |
Super good MQTT library - kudos!
It appears that the library is not thread safe.
Introducing lock protecting buffer may be difficult while supporting all hardware .
I propose to solve this by documentation:
"The pubsub library is not thread safe, in case several threads use the library following methods need to be protected
from concurrent use:
The text was updated successfully, but these errors were encountered: