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

Calling mqtt_publish inside receive message callback causes segmentation fault #88

Open
markrad opened this issue Jul 14, 2020 · 3 comments
Labels
doc update Documentation update todo Things that need to be done.

Comments

@markrad
Copy link
Contributor

markrad commented Jul 14, 2020

Possibly this is more of a documentation change than a fix.

I have an instance where I need to publish a message to the server while my code is in the received message callback function. The mqtt_publish works fine but, if one calls mqtt_sync inside that function it will crash.

@LiamBindle
Copy link
Owner

LiamBindle commented Jul 15, 2020

@markrad Yeah, I think the documentation should say something about this (IIRC this came up once before). The receive callback is called in mqtt_sync() while the mutex is locked, so calls to mqtt_sync() (along with some other functions) is not permitted. The callback is moreso meant to be like an interrupt, in that it should contain pretty minimal logic and be run quick, but that isn't explicitly documented anywhere.

Thanks for opening. I'll update the docs accordingly (unless someone else wants to do it) when I get a chance.

@learn-more
Copy link
Contributor

You might consider asserting on a situation like that,
to make it clear (also in code) that you are not supposed to do stuff like that.

@clamorel
Copy link

clamorel commented Jul 21, 2020

I'm also facing this problem.
In the simple_subscriber example I add a mqtt_publish within the publish_callback function leaving the mqtt_sync call in the client_refresher thread. This causes a segmentation fault.
Somehow the first time I tried this it worked, but now it doesn't work anymore.
I saw the publish_callback is called by mqtt_sync after locking the mutex so a mqtt_publish within the publish_callback try to lock again the mutex causing the segmentation fault.
The only way I thought to get it working is to start a new thread from the publish_callback only with the aim to send a mqtt_publish.
May this be a solution?

@LiamBindle LiamBindle changed the title SegFault Calling mqtt_publish inside receive message callback causes segmentation fault Aug 4, 2020
@LiamBindle LiamBindle added doc update Documentation update todo Things that need to be done. labels Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc update Documentation update todo Things that need to be done.
Projects
None yet
Development

No branches or pull requests

4 participants