Skip to content

deadpool-sqlite: Track object drop. #468

@xuxiaocheng0201

Description

@xuxiaocheng0201
#[tokio::test]
async fn main() -> anyhow::Result<()> {
    unsafe extern "C" fn sqlite3_test_init(
        db: *mut rusqlite::ffi::sqlite3,
        pz_err_msg: *mut *mut std::ffi::c_char,
        _p_api: *const rusqlite::ffi::sqlite3_api_routines,
    ) -> std::ffi::c_int {
        unsafe { rusqlite::auto_extension::init_auto_extension(db, pz_err_msg, |connection| {
            connection.execute_batch("SELECT 1")
        }) }
    }
    unsafe { rusqlite::auto_extension::register_auto_extension(sqlite3_test_init) }?;
    for _ in 0..2 {
        // tokio::time::sleep(tokio::time::Duration::from_millis(100)).await; // Useful
        let config = deadpool_sqlite::Config::new("file.db");
        let manager = deadpool_sqlite::Manager::from_config(&config, deadpool_sqlite::Runtime::Tokio1);
        let pool = deadpool_sqlite::Pool::builder(manager).build()?;
        let connection = pool.get().await?;
        connection.interact(|connection| {
            connection.pragma_update(None, "journal_mode", "WAL")?;
            connection.execute_batch("CREATE TABLE IF NOT EXISTS dict (key INTEGER);")?;
            Ok::<_, anyhow::Error>(())
        }).await.unwrap()?;
    }
    std::fs::remove_file("file.db")?;
    Ok(())
}
tester v0.1.0 (/Users/xuxiaocheng/Rust/tester)
├── anyhow v1.0.102
├── deadpool-sqlite v0.13.0
│   ├── deadpool v0.13.0
│   │   ├── deadpool-runtime v0.3.1
│   │   │   └── tokio v1.49.0
│   │   │       ├── pin-project-lite v0.2.16
│   │   │       └── tokio-macros v2.6.0 (proc-macro)
│   │   │           ├── proc-macro2 v1.0.106
│   │   │           │   └── unicode-ident v1.0.24
│   │   │           ├── quote v1.0.44
│   │   │           │   └── proc-macro2 v1.0.106 (*)
│   │   │           └── syn v2.0.117
│   │   │               ├── proc-macro2 v1.0.106 (*)
│   │   │               ├── quote v1.0.44 (*)
│   │   │               └── unicode-ident v1.0.24
│   │   ├── num_cpus v1.17.0
│   │   │   └── libc v0.2.182
│   │   └── tokio v1.49.0 (*)
│   ├── deadpool-sync v0.2.0
│   │   └── deadpool-runtime v0.3.1 (*)
│   └── rusqlite v0.38.0
│       ├── bitflags v2.11.0
│       ├── fallible-iterator v0.3.0
│       ├── fallible-streaming-iterator v0.1.9
│       ├── hashlink v0.11.0
│       │   └── hashbrown v0.16.1
│       │       └── foldhash v0.2.0
│       ├── libsqlite3-sys v0.36.0
│       │   [build-dependencies]
│       │   ├── cc v1.2.56
│       │   │   ├── find-msvc-tools v0.1.9
│       │   │   └── shlex v1.3.0
│       │   ├── pkg-config v0.3.32
│       │   └── vcpkg v0.2.15
│       └── smallvec v1.15.1
├── rusqlite v0.38.0 (*)
└── tokio v1.49.0 (*)

Sometimes:

Error: Error occurred while creating a new object: automatic extension loading failed: database is locked

Caused by:
    0: automatic extension loading failed: database is locked
    1: Error code 5: database is locked

Stack backtrace:
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2: std::backtrace::Backtrace::create
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/backtrace.rs:331:13
   3: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.102/src/backtrace.rs:10:14
   4: <core::result::Result<T,F> as core::ops::try_trait::FromResidual<core::result::Result<core::convert::Infallible,E>>>::from_residual
             at /Users/xuxiaocheng/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/result.rs:2189:27
   5: tester::main::{{closure}}
             at ./src/lib.rs:18:26
   6: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /Users/xuxiaocheng/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/future.rs:133:9
   7: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /Users/xuxiaocheng/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/future/future.rs:133:9
   8: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/scheduler/current_thread/mod.rs:753:70
   9: tokio::task::coop::with_budget
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/task/coop/mod.rs:167:5
  10: tokio::task::coop::budget
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/task/coop/mod.rs:133:5
  11: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}::{{closure}}
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/scheduler/current_thread/mod.rs:753:25
  12: tokio::runtime::scheduler::current_thread::Context::enter
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/scheduler/current_thread/mod.rs:442:19
  13: tokio::runtime::scheduler::current_thread::CoreGuard::block_on::{{closure}}
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/scheduler/current_thread/mod.rs:752:44
  14: tokio::runtime::scheduler::current_thread::CoreGuard::enter::{{closure}}
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/scheduler/current_thread/mod.rs:840:68
  15: tokio::runtime::context::scoped::Scoped<T>::set
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/context/scoped.rs:40:9
  16: tokio::runtime::context::set_scheduler::{{closure}}
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/context.rs:176:38
  17: std::thread::local::LocalKey<T>::try_with
             at /Users/xuxiaocheng/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:513:12
  18: std::thread::local::LocalKey<T>::with
             at /Users/xuxiaocheng/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:477:20
  19: tokio::runtime::context::set_scheduler
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/context.rs:176:17
  20: tokio::runtime::scheduler::current_thread::CoreGuard::enter
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/scheduler/current_thread/mod.rs:840:27
  21: tokio::runtime::scheduler::current_thread::CoreGuard::block_on
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/scheduler/current_thread/mod.rs:740:24
  22: tokio::runtime::scheduler::current_thread::CurrentThread::block_on::{{closure}}
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/scheduler/current_thread/mod.rs:200:33
  23: tokio::runtime::context::runtime::enter_runtime
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/context/runtime.rs:65:16
  24: tokio::runtime::scheduler::current_thread::CurrentThread::block_on
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/scheduler/current_thread/mod.rs:188:9
  25: tokio::runtime::runtime::Runtime::block_on_inner
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/runtime.rs:368:52
  26: tokio::runtime::runtime::Runtime::block_on
             at /Users/xuxiaocheng/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.49.0/src/runtime/runtime.rs:342:18
  27: tester::main
             at ./src/lib.rs:26:7
  28: tester::main::{{closure}}
             at ./src/lib.rs:2:20
  29: core::ops::function::FnOnce::call_once
             at /Users/xuxiaocheng/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  30: core::ops::function::FnOnce::call_once
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/core/src/ops/function.rs:250:5
  31: test::__rust_begin_short_backtrace
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/test/src/lib.rs:663:18
  32: test::run_test_in_process::{{closure}}
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/test/src/lib.rs:686:74
  33: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/core/src/panic/unwind_safe.rs:274:9
  34: std::panicking::catch_unwind::do_call
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/panicking.rs:581:40
  35: std::panicking::catch_unwind
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/panicking.rs:544:19
  36: std::panic::catch_unwind
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/panic.rs:359:14
  37: test::run_test_in_process
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/test/src/lib.rs:686:27
  38: test::run_test::{{closure}}
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/test/src/lib.rs:607:43
  39: test::run_test::{{closure}}
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/test/src/lib.rs:637:41
  40: std::sys::backtrace::__rust_begin_short_backtrace
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/sys/backtrace.rs:160:18
  41: std::thread::lifecycle::spawn_unchecked::{{closure}}::{{closure}}
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/thread/lifecycle.rs:92:13
  42: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/core/src/panic/unwind_safe.rs:274:9
  43: std::panicking::catch_unwind::do_call
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/panicking.rs:581:40
  44: std::panicking::catch_unwind
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/panicking.rs:544:19
  45: std::panic::catch_unwind
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/panic.rs:359:14
  46: std::thread::lifecycle::spawn_unchecked::{{closure}}
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/thread/lifecycle.rs:90:26
  47: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/core/src/ops/function.rs:250:5
  48: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/alloc/src/boxed.rs:2206:9
  49: std::sys::thread::unix::Thread::new::thread_start
             at /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf/library/std/src/sys/thread/unix.rs:118:17
  50: __pthread_cond_wait

I think this is a similar problem to #330

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sqliteArea: SQLite / deadpool-sqliteenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions