sled icon indicating copy to clipboard operation
sled copied to clipboard

Concurrent Tree::flush_async deadlocks on v0.34.6 (latest release)

Open ghost opened this issue 4 years ago • 3 comments

rustc 1.50.0 (cb75ad5db 2021-02-10) sled v0.34.6 (latest release) on platform x86_64-pc-windows-msvc and x86_64-apple-darwin

Concurrently calling flush_async on the same tree causes deadlock. A minimal example:

use futures::{
    stream::{self, StreamExt},
    FutureExt,
};
use std::env::temp_dir;

#[tokio::main]
async fn main() -> sled::Result<()> {
    let db = sled::open(temp_dir())?;

    let sets = (0..100).map(|i| {
        let db = db.clone();
        async move {
            db.insert(&[i], vec![0])?;
            db.flush_async().await?;
            Ok::<(), sled::Error>(())
        }
    });

    stream::iter(sets)
        .for_each_concurrent(None, |fut| fut.map(|_| ()))
        .await;
    Ok(())
}

dependencies:

[dependencies]
futures = "0.3.13"
sled = "0.34.6"
tokio = { version = "1.3.0", features = ["full"] }

However the program above won't deadlock on main, bisect shows 61803984dc1cd8c35a3d537c2a7f5538fa659fac has fixed it.

ghost avatar Mar 20 '21 19:03 ghost

For me, this only seems to happen when compiling in release mode, and not in debug mode.

Using main does indeed fix this issue.

Frederik-Baetens avatar Mar 26 '22 16:03 Frederik-Baetens

@spacejam this has "fixed in main branch" on this issue for almost a year, can this issue be closed, or is it not solved?

ShadowJonathan avatar Mar 26 '22 17:03 ShadowJonathan

Perhaps a new release of sled with the fix included would be nice, so that new users don't run into this anymore?

Frederik-Baetens avatar Mar 26 '22 17:03 Frederik-Baetens