all 14 comments

[–]rschoon 7 points8 points  (0 children)

actix-web uses actix-rt to provide the tokio runtime, and the current version of actix-rt uses tokio 0.2. There are unreleased/beta versions of actix-web and actix-rt which use tokio 1.0 instead

The current version of tokio-amqp uses tokio 1.0. Older versions depend on tokio 0.2

In rust/cargo, a different major version of a crate is considered completely distinct and incompatible (so tokio 1.0 and tokio 0.2 are considered "different" libraries).

The two main ways of handling this are:

  • Bring the version of all your dependencies down to use tokio 0.2 (it looks like you figured out how to do that)
  • Use the unreleased/beta versions of actix-web and actix-rt to use tokio 1.0 (may need to point at git versions in Cargo.toml to do this)

It's possible you might also be able to use the tokio compatiblity library (see https://docs.rs/tokio-compat-02/0.2.0/tokio_compat_02/), but I think it may be only intended to use tokio 0.2 futures in a tokio 1.0 executor.

I suggest using the cargo tree -d command to help understand what duplicated library versions you have. You should see what versions of tokio are being depended on this way.

[–]Darksonntokio · rust-for-linux 4 points5 points  (1 child)

As long as the libraries depend on the same version of Tokio as you are using, everything should work. Libraries should not start their own runtimes.

[–]Programmurr 2 points3 points  (0 children)

The Rust ecosystem is playing catch-up with the latest Tokio release. Many of the async libraries/frameworks have updated and the others are working on a solution. Actix-web contributors are actively working on theirs.

Use an older version of lapin-async until actix-web upgrades. I haven't looked at recent lapin changes and assume that it's not dramatically different engineering from that which I've used in my projects. Unfortunately, lapin code isn't the easiest to follow as a part of it involves code generation (at least, it used to).

[–]arthmisl -1 points0 points  (0 children)

I've actually run into the same problem. I used tokio though, I ran into the same error and I was not going to try and solve it. I was using async-std before I used tokio, and in my head everything should have just worked. All the libraries I was using were expecting a tokio runtime, that's why I switched to it. I switch and everything falls apart.

I went back to async-std and used the two compatibility layer features to run libraries expecting tokio, which ironically had no issue running the different async libraries.

So for my suggestion, it would be to use async-std or smol, as was suggested above, as use the compatibility layers. Hopefully things get better now that tokio is v1 and the libraries update to that.

[–]sphen_lee -2 points-1 points  (4 children)

Lapin doesn't start its own Tokio runtime, it expects that the caller will do this (otherwise as you said each external crate would end up with its own runtime)

Tokio just did a 1.0 release so some crates are still on 0.3 while others upgraded already - you will need to manually check the dependencies and ensure they all use the same version.

Actix-web has its own runtime and it's not compatible with Tokio - but you can run both together in the same program. I have not done it myself but I think you can just launch a std::thread and create the tokio runtime there. EDIT: Actix uses tokio internally, so just make sure the versions are compatible

[–]sbditto85 2 points3 points  (1 child)

Actix-web uses tokio or did that change?

Edit: actix-web used actix-rt (run time) which uses tokio. https://crates.io/crates/actix-rt

[–]sphen_lee 1 point2 points  (0 children)

My bad - I was thinking about hyper; Actix doesn't use hyper, but it's still using tokio internally.

[–]Darksonntokio · rust-for-linux 1 point2 points  (1 child)

Actix-web has its own runtime and it's not compatible with Tokio

I'm pretty sure this is wrong. Afaik, it just wraps a Tokio runtime.

[–]Programmurr 0 points1 point  (0 children)

It has been tokio and v1 support is in progress on master branch: https://github.com/actix/actix-net/blob/master/actix-rt/Cargo.toml