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

mosquitto_connect_bind_v5() and mosquitto_loop_forever() not working in detached thread #2913

Open
luismigb opened this issue Oct 2, 2023 · 0 comments

Comments

@luismigb
Copy link

luismigb commented Oct 2, 2023

Hi,

I am working with version 2.0.18 cross compiling for ARM (Raspberry Pi).

I want to run a detached thread with any of mosquitto_loop... APIs (to be able to execute other application threads), but I am not able to get it working, only when it is called from the main thread.

I have created a class with a Start method which initialize required fields from mosq_config struct and call all mosquitto APIs to configure TLS and callbacks.
Then, if I call mosquitto_connect_bind_v5 and then mosquitto_loop_forever (inside Start method), this connects and subscribe to broker correctly.
But if I move those two functions to a detached thread run from Start method, mosquitto_connect_bind_v5 fails (sometimes) with "Bad file descriptor" or most of the time with "A TLS error occurred".

Debugging this I get:

4063442928 [ERROR] [MosquittoClient::LogCallback] Error: Unable to load CA certificates, check cafile "▒3▒▒".
4063442929 [ERROR] [MosquittoClient::LogCallback] OpenSSL Error[0]: error:02001002:system library:fopen:No such file or directory
4063442929 [ERROR] [MosquittoClient::LogCallback] OpenSSL Error[1]: error:2006D080:BIO routines:BIO_new_file:no such file
4063442930 [ERROR] [MosquittoClient::LogCallback] OpenSSL Error[2]: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib

Which means that mqttClient->tls_cafile lost its content after the thread creation and because of that the connection is never established.

Attached there is a reduced sample of the class I have created.

MosquittoClient.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant