tursodatabase / libsql-client-rs

libSQL Rust client library can be used to communicate with sqld natively over HTTP protocol with native Rust interface.
MIT License
75 stars 27 forks source link

SyncClient hangs #48

Open hangj opened 12 months ago

hangj commented 12 months ago

The async Client works just fine, but the following SyncClient hangs:

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
    let db = libsql_client::SyncClient::from_env()?;
    let response = db.execute("SELECT * FROM users")?;

    println!("{:?}", response);

    Ok(())
}
psarna commented 12 months ago

Thanks for reporting @hangj! I see that SyncClient gets stuck with your example, and gets unblocked once I change it from #[tokio::main(flavor = "current_thread")] to just #[tokio::main], so we probably block the current thread for something... I'll dig further

psarna commented 12 months ago

yeah, it's due to the fact we call futures::executor::block_on underneath, which clashes with single-threaded tokio runtime

hangj commented 12 months ago

Yeah, that's the reason.

But the real problem I think is that the libsql_client::SyncClient is not a real blocking client, I have to choose a runtime for it.