eclipse / paho.mqtt.rust

paho.mqtt.rust
Other
516 stars 102 forks source link

[Soundness] Callbacks are run on different threads, but are not required to be `Send` #182

Closed Alxandr closed 1 year ago

Alxandr commented 1 year ago

I've been trying to figure out a bug I had using paho-mqtt, where I couldn't spawn local tasks in a LocalSet from tokio, so I decided to add some logging of the current thread ID:

        println!("thread-id: {:?}", std::thread::current().id());
        let not_send = NotSendValue;

        client.set_connected_callback({
            move |c| {
                println!("thread-id: {:?}{:?}", std::thread::current().id(), NotSendValue);
            }
        });

This results in printing two different thread numbers (18 and 20 in my specific case), and I'm allowed to use my not_send value from both threads, which is unsound.

fpagliughi commented 1 year ago

Yes! d9cecc4 should fix it.