inejge / ldap3

A pure-Rust LDAP library using the Tokio stack
Apache License 2.0
226 stars 39 forks source link

Incompatibility with tokio 0.3.0 #59

Closed eutampieri closed 4 years ago

eutampieri commented 4 years ago

The following code produces this error:

panicked at 'must be called from the context of Tokio runtime configured with either `basic_scheduler` or `threaded_scheduler`', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.3.0/src/task/spawn.rs:131:10 PanicInfo { payload: Any, message: Some(must be called from the context of Tokio runtime configured with either `basic_scheduler` or `threaded_scheduler`), location: Location { file: "/usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.3.0/src/task/spawn.rs", line: 131, col: 10 } }
if let Ok((conn, mut ldap)) = ldap3::LdapConnAsync::new("ldap://10.10.9.3:389").await {
        ldap3::drive!(conn);
}
inejge commented 4 years ago

Right, the library requires Tokio 0.2. I don't think you can use a 0.2 future directly on a 0.3 runtime, you need to go through a compatibility layer. I'll push a 0.3 port on master soon.

inejge commented 4 years ago

Try 0.8.0, just published.

inejge commented 4 years ago

@eutampieri Does 0.8.0 work for you? If so, I'd like to close the issue.

eutampieri commented 4 years ago

If it’s not a problem I’ll try later today

eutampieri commented 4 years ago

So, my use case is to bind to an LDAP server inside an Actix-web route, but it doesn't work. The error now is

thread 'actix-rt:worker:0' panicked at 'there is no reactor running, must be called from the context of Tokio runtime', /Users/eugeniotampieri/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.3.1/src/io/driver/mod.rs:232:18

The code is

#[post("/login")]
pub async fn login(params: web::Form<LoginDetails>, sessions: SessionsRW) -> impl Responder {
    let username = &params.username;
    let password = &params.password;
    if let Ok((conn, mut ldap)) = ldap3::LdapConnAsync::new(LDAP_ADDRESS).await {
         ldap3::drive!(conn);
        // do stuff
    }
}
inejge commented 4 years ago

Well that's something else; did you integrate Actix-web and Tokio by way of actix_rt, as seen, e.g., in actix/actix-web#1283? Note that the current version of actix_rt requires Tokio 0.2, so you'll have to use ldap3 0.7 anyway.

eutampieri commented 4 years ago

Sorry, my bad