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

version incompatibility with async libraries #79

Closed
nikomatsakis opened this issue Mar 22, 2021 · 6 comments
Closed

version incompatibility with async libraries #79

nikomatsakis opened this issue Mar 22, 2021 · 6 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed status-quo-story-ideas "Status quo" user story ideas

Comments

@nikomatsakis
Copy link
Contributor

Brief summary:

I feel a lot like Alan. An annoying situation which is happening to me in async Rust is having to handle dependencies which needs different versions of the same runtime (tokio's transition to 1.0). I feel like "doing cargo's work" when I have to find the right combination of features and versions on my dependencies just to be able to run my code without panics.

Originally posted by @eduardocanellas in #70 (comment)

Optional details

  • Key takeaways
    • Managing nitty gritty versions is annoying
    • Have to understand more impl details than you want to, perhaps?
@nikomatsakis nikomatsakis added good first issue Good for newcomers help wanted Extra attention is needed status-quo-story-ideas "Status quo" user story ideas labels Mar 22, 2021
@eminence
Copy link
Contributor

Things these days are better, as the ecosystem has been steadily moving toward tokio 1.0. In order to reproduce this type of situation, I had to "cheat" a little bit, by deliberately using a version of a library that is a few months old (so that it would depend on an older version of tokio). But I'm certain a variant of this problem would have been possible to stumble upon in the wild sometime in late 2019.

This project uses the latest tokio (1.0) and tokio-tungstenite version 0.12, which requires tokio 0.3. This version of tokio-tungstenite was released November 2020.

[dependencies]
tokio-tungstenite = "0.12.0"
tokio = { version = "1", features = ["rt", "full"] }

The code looks like this:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let _ = tokio_tungstenite::connect_async("ws://localhost:8080").await;

    Ok(())
}

Cargo can resolve the package dependency tree without errors, and the code compiles without errors. But at runtime:

   Compiling foo v0.1.0 (C:\Users\achin\tmp\19\foo)
    Finished dev [unoptimized + debuginfo] target(s) in 1.74s
     Running `target\debug\foo.exe`
thread 'main' panicked at 'requires the `rt` Tokio feature flag', C:\Users\achin\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.3.7\src\blocking.rs:18:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\foo.exe` (exit code: 101)

This error especially fun because if we look at our Cargo.toml, we can see that explicitly enabled the "rt" feature flag on tokio (or at least it appears that way)

@dbofmmbt
Copy link

dbofmmbt commented Mar 23, 2021

@eminence an example without "cheating" would be actix web right now. It has no version with support to Tokio 1.0 today. If you try to use it with the latest version of reqwest or sqlx, you're gonna get in trouble.

@eminence
Copy link
Contributor

@eduardocanellas great point, thanks!

#[actix_web::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {

    let body = reqwest::get("https://www.rust-lang.org")
    .await?
    .text()
    .await?;

    Ok(())
}

The above code gives us our favorite panic:

thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime'

@nikomatsakis
Copy link
Contributor Author

This is covered decently well in https://rust-lang.github.io/wg-async-foundations/vision/status_quo/alan_picks_web_server.html -- closing

@danik4985
Copy link

@nikomatsakis that link points to a 404 page

@tmandry
Copy link
Member

tmandry commented Nov 10, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed status-quo-story-ideas "Status quo" user story ideas
Projects
None yet
Development

No branches or pull requests

5 participants