bytebeamio / rumqtt

The MQTT ecosystem in rust
Apache License 2.0
1.64k stars 252 forks source link

v5::EventLoop not Send when websocket is enabled #769

Closed kaans closed 11 months ago

kaans commented 11 months ago

Expected Behavior

When enabling the feature "websocket", the v5::EventLoop should still be Send as it is the case when "websocket" is not enabled.

Current Behavior

The v5::EventLoop is not Send anymore, even though the documentation states that the trait Send is implemented.

Failure Information (for bugs)

error: future cannot be sent between threads safely
--> src\main.rs:24:24
|
24  |       tokio::task::spawn(async move {
|  ________________________^
25  | |         loop {
26  | |             match event_loop.poll().await {
27  | |                 Ok(event) => {
...   |
39  | |         }
40  | |     })
| |_____^ future created by async block is not `Send`
|
= help: the trait `Sync` is not implemented for `(dyn Fn(http::request::Request<()>) -> Pin<Box<(dyn Future<Output = http::request::Request<()>> + 'static)>> + 'static)`
note: captured value is not `Send`
--> src\main.rs:26:19
|
26  |             match event_loop.poll().await {
|                   ^^^^^^^^^^ has type `rumqttc::v5::EventLoop` which is not `Send`
note: required by a bound in `tokio::spawn`
--> C:\..path..to..\index.crates.io-6f17d22bba15001f\tokio-1.35.0\src\task\spawn.rs:166:21
|
164 |     pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
|            ----- required by a bound in this function
165 |     where
166 |         F: Future + Send + 'static,
|                     ^^^^ required by this bound in `spawn`

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

Repository with example code: https://github.com/kaans/rumqttc_websocket_error

Failure Logs

Please include any relevant log snippets or files here.

swanandx commented 11 months ago

Thank you for reporting and providing example to reproduce the bug!

looks like the issue is only in v5 due to use of http::Request here.

I will have to see why we have that request modifier and what can we do about it! thanks for reporting it! will keep you updated.

swanandx commented 11 months ago

Hey @kaans , PR to fix this behaviour is merged 🎉

Thanks for reporting the issue!

kaans commented 11 months ago

Thanks a lot for the very quick fix! I'll try it out as soon as I can.