-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Crash during mosquitto_kick_client_by_clientid call #3080
Comments
Same experience here. The only Idea I had so far was to slow down the messages what didnt have an effect. |
@dkelmatic: |
I think there is a I don't remember if this is available in 2.0.14 though. |
That sounds like a very good idea. I will try this approach. Thanks! |
Hey! |
Why would you need to recompile mosquitto for that? Just trying to follow your train of thought here, on how you arrive to this. |
I can confirm that "tick" is available. We use and build our own Mosquitto plugin. Thus, it is no problem to have a thread-safe mechanism that handles the access to the list. I implemented it using C++ sync mechanisms. Testing is still pending.
IMO you don't. You compile your plugin. See above. |
Maybe I'm thinking wrong, but when I use a list for the clients to be kicked on the next tick, I would fill the list from within the same thread I try to kick the clients in my current implementation. I would then kick the clients in my tick event, that has been triggered by the mosquitto main loop thread. When adding/deleting the entries from the list, I would probably have to make sure that the two threads are not accessing the list in the same time to avoid another race condition. Wouldn't I have to set such a semaphore up within the mqoauitto main code then? |
The tick event can be handled in a plugin. You can register a handler function there. No need to modify Mosquitto itself, but you extend it with a plugin. |
Yes, I understand the the plugin interface. I'm using an oauth plugin. |
I'm not convinced mosquitto runs ACL checks in parallel with multiple threads, so maybe you don't need the mutex or semaphore. However, just for thought, why can't the semaphore be next to the list within the plugin? |
Hey @Daedaluz , I will report back whn I have results. |
Hello everyone, In the acl event I add clients to the list (if they are not already in there) with help of the received userdata pointer and in the tick event I kick the users. I didn't find a safe way to reproduce my crashes with the old solution, but until now I didn't experience any crash in the testing environment with the new solution. Fingers crossed 🤞 Did you solve the issue for your plugin? @D-r-P-3-p-p-3-r ? |
@dkelmatic Thus, this is a good/the solution. It'd be great if this information would be added to the documentation. It makes totally sense that you have to do it this way. But it is not quite obvious IMO. |
can we close? =) or maybe follow up on DrP3pp3rs suggestion. |
I've added a comment to mosquitto_broker.h that should address this. |
I like the explanation. Will it show up in the docs as well? |
Yes, good explanation, but I think I would add the other case in here too; However, I do not know if it shold be possible / safe to kick clients from this specific callback or not. It just made more sense to me to do all the acl checking and then - in a tick callback - kick clients no longer welcome. |
Hello folks, @Daedaluz yes I agree. I most probably tried to kick clients twice by f*cking up my kick list. |
We're experiencing crashes when calling mosquitto_kick_client_by_clientid under Mosquitto 2.14. Because of issue #3056 we're not using a newer version of Mosquitto (which probably does not matter).
Scenario: We are running a self-written Mosquitto Plug-In. This plugin keeps a white list of devices that are allowed to connect to the broker. The white list content is set by an application via an REST API. If a device is removed from the white list and it is currently connected to the broker we kick it via mosquitto_kick_client_by_clientid . This happens in a thread that is started by the plugin (the thread that handles all the plug-in‘s logic). Occasionally during the calls to mosquitto_kick_client_by_clientid the broker crashes.
I suspect it happens when concurrently with the mosquitto_kick_client_by_clientid call an ACL check is performed in the plugin via Mosquitto.
Before entering the plug-in thread we're extracting information from the event_data (e.g. via mosquitto_client_id(), mosquitto_client_username(), mosquitto_client_certificate()) in Mosquittos own thread.
Is it not ok to call mosquitto_kick_client_by_clientid from a thread that is not Mosquitto's?
Or is the problem that mosquitto_kick_client_by_clientid and mosquitto_client_* are called at the same time from different threads?
Or are there other rules I am not aware of?
Unlike the libmosquitto documentation which states the following
the plug-in documentation does not talk about thread safety at all.
The text was updated successfully, but these errors were encountered: