BiagioFesta / wtransport

Async-friendly WebTransport implementation in Rust
Apache License 2.0
470 stars 31 forks source link

`DnsLookupFuture` does not implement `Send` #206

Closed JimitSoni18 closed 3 months ago

JimitSoni18 commented 3 months ago

I upgraded from 0.1.13 and noticed that one of my test no longer compiles. The test tries to spawn a client using tokio like so:

        let client_join = tokio::spawn(async {
            let client = Endpoint::client(ClientConfig::default()).unwrap();
            let connection =
                client.connect("https://localhost:4433").await.unwrap();
            let (_, mut recv) =
                connection.open_bi().await.unwrap().await.unwrap();
            let msg = recv.read_message().await.unwrap();
            let result = std::str::from_utf8(&msg).unwrap();
        });

but the future returned by client.connect(...) was not Send

here is the full error:

error[E0277]: `dyn DnsLookupFuture` cannot be sent between threads safely
    --> src/framing/mod.rs:255:21
     |
255  |           let client_join = tokio::spawn(async {
     |  ___________________________^
256  | |             let client = Endpoint::client(ClientConfig::default()).unwrap();
257  | |             let connection =
258  | |                 client.connect("https://localhost:4433").await.unwrap();
...    |
262  | |             let result = std::str::from_utf8(&msg).unwrap();
263  | |         });
     | |__________^ `dyn DnsLookupFuture` cannot be sent between threads safely
     |
     = help: the trait `Send` is not implemented for `dyn DnsLookupFuture`, which is required by `{async block@src/framing/mod.rs:255:34: 263:4}:
 Send`
     = note: required for `Unique<dyn DnsLookupFuture>` to implement `Send`
note: required because it appears within the type `Box<dyn DnsLookupFuture>`
    --> /home/hi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:237:12
     |
237  | pub struct Box<
     |            ^^^
note: required because it appears within the type `Pin<Box<dyn DnsLookupFuture>>`
    --> /home/hi/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/pin.rs:1090:12
     |
1090 | pub struct Pin<Ptr> {
     |            ^^^
note: required because it's used within this `async` fn body
    --> /home/hi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wtransport-0.2.0/src/endpoint.rs:296:5
     |
296  | /     {
297  | |         let options = options.into_options();
298  | |
299  | |         let url = Url::parse(&options.url)
...    |
446  | |         Ok(Connection::new(quic_connection, driver, session_id))
447  | |     }
     | |_____^
note: required because it's used within this `async` block
    --> src/framing/mod.rs:255:34
     |
255  |           let client_join = tokio::spawn(async {
     |  ________________________________________^
256  | |             let client = Endpoint::client(ClientConfig::default()).unwrap();
257  | |             let connection =
258  | |                 client.connect("https://localhost:4433").await.unwrap();
...    |
262  | |             let result = std::str::from_utf8(&msg).unwrap();
263  | |         });
     | |_________^
note: required by a bound in `tokio::spawn`
    --> /home/hi/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.40.0/src/task/spawn.rs:167:21
     |
165  |     pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
     |            ----- required by a bound in this function
166  |     where
167  |         F: Future + Send + 'static,
     |                     ^^^^ required by this bound in `spawn`

For more information about this error, try `rustc --explain E0277`.
warning: `transport-io` (lib test) generated 1 warning
error: could not compile `transport-io` (lib test) due to 1 previous error; 1 warning emitted
BiagioFesta commented 3 months ago

Oh I've missed that during code refactoring.

Sorry about that and thank you for reproducing and report that :)

JimitSoni18 commented 3 months ago

Thanks, the refactoring looks good