kardeiz/bb8-tiberius

main wants another tokio 1.x runtime while already inside one (actix-web)

Opened this issue · 2 comments

SCOPE
I want to create a project with actix-web and tiberius, using bb8-tiberius as pool being propagated through the application state of actix-web.

CODE TO REPRODUCE
My current revision is benjaminweb/actix-bb8-tiberius@b5a13bb

CURRENT BEHAVIOUR
cargo run raises a:

thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /Users/benjaminweb/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.4.0/src/runtime/context.rs:37:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Panic in Arbiter thread.

EXPECTED BEHAVIOUR
Considering pg as reference implementation, there is no dedicated tokio runtime necessary as it already happens inside a tokio runtime, that of actix_web:
https://github.com/actix/examples/blob/master/database_interactions/pg/src/main.rs#L95-L124

Also, @pimeys hinted me that there would be no additional tokio runtime required.
The present behaviour might be a potential bug.

@kardeiz, I appreciate your effort in resolving this issue.

Once working, I want to publish the project as a quick-starter boilerplate actix-web, tiberius (MSSQL).

@benjaminweb Hi, thanks for the issue. It looks like actix-web 3.x is using the older 0.2 version of Tokio (via actix-rt 1.1.1).

You can set up actix-web 3.x to use an existing Tokio runtime as described here: actix/actix-web#1283.

However, I haven't kept up with the latest in Tokio 1.x compatibility interfaces. You would probably need to wrap the Tokio 1.x runtime/LocalSet in a 0.2 compatibility wrapper before passing it to actix-rt.

Other options would be to use/wait for actix-web 4.x (looks like it is in beta currently), or see if actix-web 3.x can be set up to use the latest version of actix-rt (2.2).