Panic in `libsql` crate when using connection concurrently
Opened this issue · 1 comments
Allypost commented
In some heavily concurrent cases, accessing a local DB connection will panic inside the libsql crate:
thread 'tokio-runtime-worker' panicked at …/libsql-0.9.17/src/local/connection.rs:19:10:
already mutably borrowed: BorrowError
I couldn't quite get it to reproduce reliably, but the following should trigger a panic after a couple invocations:
# Cargo.toml
[dependencies]
libsql = "0.9.17"
tokio = "1.46.1"// main.rs
#[tokio::main]
async fn main() {
let conn = libsql::Builder::new_local(":memory:")
.build()
.await
.unwrap()
.connect()
.unwrap();
let mut js = tokio::task::JoinSet::new();
for _ in 0..5000 {
let conn = conn.clone();
js.spawn(async move {
conn.query("SELECT datetime('now')", libsql::params![])
.await
.unwrap();
});
}
println!("Waiting...");
js.join_all().await;
println!("Done");
}I only managed to get the error in dev mode for this minimal example (just plain cargo run). It doesn't trigger every time, but should trigger within 10 or so runs:
true; while [ $? -eq 0 ]; do cargo run; done
Full error with RUST_BACKTRACE=full
thread 'tokio-runtime-worker' panicked at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libsql-0.9.17/src/local/connection.rs:19:10:
already mutably borrowed: BorrowError
stack backtrace:
0: 0x562b21453632 - std::backtrace_rs::backtrace::libunwind::trace::h74680e970b6e0712
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
1: 0x562b21453632 - std::backtrace_rs::backtrace::trace_unsynchronized::ha3bf590e3565a312
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
2: 0x562b21453632 - std::sys::backtrace::_print_fmt::hcf16024cbdd6c458
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:66:9
3: 0x562b21453632 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h46a716bba2450163
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:39:26
4: 0x562b21474733 - core::fmt::rt::Argument::fmt::ha695e732309707b7
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/fmt/rt.rs:181:76
5: 0x562b21474733 - core::fmt::write::h275e5980d7008551
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/fmt/mod.rs:1446:25
6: 0x562b214509c3 - std::io::default_write_fmt::hdc4119be3eb77042
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/mod.rs:639:11
7: 0x562b214509c3 - std::io::Write::write_fmt::h561a66a0340b6995
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/mod.rs:1914:13
8: 0x562b21453482 - std::sys::backtrace::BacktraceLock::print::hafb9d5969adc39a0
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:42:9
9: 0x562b21454852 - std::panicking::default_hook::{{closure}}::hae2e97a5c4b2b777
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:300:22
10: 0x562b21454655 - std::panicking::default_hook::h3db1b505cfc4eb79
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:327:9
11: 0x562b214551f2 - std::panicking::rust_panic_with_hook::h409da73ddef13937
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:833:13
12: 0x562b21454f9a - std::panicking::begin_panic_handler::{{closure}}::h159b61b27f96a9c2
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:706:13
13: 0x562b21453b29 - std::sys::backtrace::__rust_end_short_backtrace::h5b56844d75e766fc
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:168:18
14: 0x562b21454c2d - __rustc[4794b31dd7191200]::rust_begin_unwind
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:697:5
15: 0x562b20b481a0 - core::panicking::panic_fmt::hc8737e8cca20a7c8
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:75:14
16: 0x562b20b480f3 - core::cell::panic_already_mutably_borrowed::h95c7d326eb19a92a
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/cell.rs:799:5
17: 0x562b20c8710f - core::cell::RefCell<T>::borrow::h38d7aedf64c8150e
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cell.rs:987:25
18: 0x562b20c8710f - <core::cell::RefCell<T> as core::clone::Clone>::clone::hc675c25ccbe5c020
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/cell.rs:1302:27
19: 0x562b20d706e9 - <libsql::local::connection::Connection as core::clone::Clone>::clone::h33be49a772f66609
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libsql-0.9.17/src/local/connection.rs:28:5
20: 0x562b20d6a435 - libsql::local::connection::Connection::prepare::he30978d05e840cb7
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libsql-0.9.17/src/local/connection.rs:109:28
21: 0x562b20d7141c - <libsql::local::impls::LibsqlConnection as libsql::connection::Conn>::prepare::{{closure}}::h8901f7b8f2bdaf96
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libsql-0.9.17/src/local/impls.rs:39:20
22: 0x562b20d0c5c0 - <core::pin::Pin<P> as core::future::future::Future>::poll::h112f2addff4e9b60
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:124:9
23: 0x562b20b67c3a - libsql::connection::Connection::prepare::{{closure}}::hf8f8084532d27740
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libsql-0.9.17/src/connection.rs:181:32
24: 0x562b20b66cea - libsql::connection::Connection::query::{{closure}}::h62410fdc2d648aad
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libsql-0.9.17/src/connection.rs:173:42
25: 0x562b20b49b11 - libsql_panic::main::{{closure}}::{{closure}}::h84c144d58738b96c
at /tmp/tmp.5Tvrf1RVqX/libsql-panic/src/main.rs:15:18
26: 0x562b20b61992 - tokio::runtime::task::core::Core<T,S>::poll::{{closure}}::h4ab39092b5988a83
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/core.rs:365:17
27: 0x562b20b614dd - tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut::he6628f0a2f0a3793
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/loom/std/unsafe_cell.rs:16:9
28: 0x562b20b614dd - tokio::runtime::task::core::Core<T,S>::poll::h83fd04f350a36488
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/core.rs:354:13
29: 0x562b20b538da - tokio::runtime::task::harness::poll_future::{{closure}}::h797f0bbc019cf255
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/harness.rs:535:19
30: 0x562b20b62a70 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h2eab4983440347d7
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:272:9
31: 0x562b20b5a644 - std::panicking::try::do_call::ha49ad2e6c7093cc2
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:589:40
32: 0x562b20b4bcbb - __rust_try
33: 0x562b20b4b476 - std::panicking::try::hcffc597dd0cb39e8
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:552:19
34: 0x562b20b4b476 - std::panic::catch_unwind::h7145e79dfad506df
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14
35: 0x562b20b5300f - tokio::runtime::task::harness::poll_future::h1a46cbde83f48843
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/harness.rs:523:18
36: 0x562b20b53f01 - tokio::runtime::task::harness::Harness<T,S>::poll_inner::ha96072653a7dcc1a
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/harness.rs:210:27
37: 0x562b20b54933 - tokio::runtime::task::harness::Harness<T,S>::poll::h755ae60d7e461144
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/harness.rs:155:15
38: 0x562b20b683fb - tokio::runtime::task::raw::poll::h1f95aea937c16d66
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/raw.rs:325:5
39: 0x562b21398c37 - tokio::runtime::task::raw::RawTask::poll::h3b3efc56acbb86b8
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/raw.rs:255:18
40: 0x562b213a0c32 - tokio::runtime::task::LocalNotified<S>::run::hf750322e05007930
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/mod.rs:509:9
41: 0x562b213bed6d - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::{{closure}}::haf8da7375840382e
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/scheduler/multi_thread/worker.rs:600:13
42: 0x562b213bebc9 - tokio::task::coop::with_budget::hb01e55957ed7e6bc
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/task/coop/mod.rs:167:5
43: 0x562b213bebc9 - tokio::task::coop::budget::h3588977b769f175f
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/task/coop/mod.rs:133:5
44: 0x562b213bebc9 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::hf769b569a7cd57a1
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/scheduler/multi_thread/worker.rs:591:9
45: 0x562b213bdff1 - tokio::runtime::scheduler::multi_thread::worker::Context::run::h98c5ccbc73ebaf50
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/scheduler/multi_thread/worker.rs:539:24
46: 0x562b213bda59 - tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}::{{closure}}::hef8948bb1b2788de
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/scheduler/multi_thread/worker.rs:504:21
47: 0x562b213e5f20 - tokio::runtime::context::scoped::Scoped<T>::set::h25b5eebe79cc595e
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/context/scoped.rs:40:9
48: 0x562b2139624b - tokio::runtime::context::set_scheduler::{{closure}}::he9d8321fc4395bba
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/context.rs:176:26
49: 0x562b2137230b - std::thread::local::LocalKey<T>::try_with::hfa6dab202e6ec9b5
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:315:12
50: 0x562b213706af - std::thread::local::LocalKey<T>::with::h46290d0ad514e668
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:279:15
51: 0x562b21396184 - tokio::runtime::context::set_scheduler::h30b65b1061aa2db4
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/context.rs:176:9
52: 0x562b213bd964 - tokio::runtime::scheduler::multi_thread::worker::run::{{closure}}::h071ae52d1ef18e3d
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/scheduler/multi_thread/worker.rs:499:9
53: 0x562b2139f8a2 - tokio::runtime::context::runtime::enter_runtime::hbf92670852307098
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/context/runtime.rs:65:16
54: 0x562b213bd711 - tokio::runtime::scheduler::multi_thread::worker::run::h9f55f2f31512c0aa
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/scheduler/multi_thread/worker.rs:491:5
55: 0x562b213bd3fb - tokio::runtime::scheduler::multi_thread::worker::Launch::launch::{{closure}}::h1442e8328ce82046
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/scheduler/multi_thread/worker.rs:457:45
56: 0x562b2139a66e - <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll::hfc482ea1015a2bdc
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/blocking/task.rs:42:21
57: 0x562b2136c586 - tokio::runtime::task::core::Core<T,S>::poll::{{closure}}::hd635f9ba8fb0ce29
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/core.rs:365:17
58: 0x562b2136b451 - tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut::h88f6f442e4f398da
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/loom/std/unsafe_cell.rs:16:9
59: 0x562b2136b451 - tokio::runtime::task::core::Core<T,S>::poll::h7378d426a3474733
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/core.rs:354:13
60: 0x562b213676ee - tokio::runtime::task::harness::poll_future::{{closure}}::hca732611cf9fcc0e
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/harness.rs:535:19
61: 0x562b213c3e91 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h7e88f9bcbac1fe56
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:272:9
62: 0x562b213932a5 - std::panicking::try::do_call::h310fce93bb2d2f3e
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:589:40
63: 0x562b213d540b - __rust_try
64: 0x562b213cee86 - std::panicking::try::h4640f68a09af0a7a
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:552:19
65: 0x562b213cee86 - std::panic::catch_unwind::h00afa0b15c52a39d
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14
66: 0x562b21365c20 - tokio::runtime::task::harness::poll_future::h1c02a8a3fb1e76a9
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/harness.rs:523:18
67: 0x562b213628c8 - tokio::runtime::task::harness::Harness<T,S>::poll_inner::he42894139f8d8c86
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/harness.rs:210:27
68: 0x562b21361d47 - tokio::runtime::task::harness::Harness<T,S>::poll::hb6a54f6038269cf4
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/harness.rs:155:15
69: 0x562b21398f9d - tokio::runtime::task::raw::poll::h5ad81cd303944cf8
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/raw.rs:325:5
70: 0x562b21398c37 - tokio::runtime::task::raw::RawTask::poll::h3b3efc56acbb86b8
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/raw.rs:255:18
71: 0x562b213a0cf7 - tokio::runtime::task::UnownedTask<S>::run::he8440bd5275f6de8
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/task/mod.rs:546:9
72: 0x562b213e9d97 - tokio::runtime::blocking::pool::Task::run::h35b149eb4eb21ccf
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/blocking/pool.rs:161:9
73: 0x562b213ee9bd - tokio::runtime::blocking::pool::Inner::run::hdd956e89fa9f87c3
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/blocking/pool.rs:516:17
74: 0x562b213ee6e4 - tokio::runtime::blocking::pool::Spawner::spawn_thread::{{closure}}::h595abafc666c3af2
at /home/allypost/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.46.1/src/runtime/blocking/pool.rs:474:13
75: 0x562b213a29f6 - std::sys::backtrace::__rust_begin_short_backtrace::h6f27ecef73d51e66
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18
76: 0x562b213a4112 - std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}::h06fe4a5b860f08fe
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:559:17
77: 0x562b213c3d31 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h4a1e0ced30751c13
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:272:9
78: 0x562b21393660 - std::panicking::try::do_call::h7c0cc3eb5fd1e9b3
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:589:40
79: 0x562b213aad7b - __rust_try
80: 0x562b213a3ee4 - std::panicking::try::h4c7517651a9aa55c
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:552:19
81: 0x562b213a3ee4 - std::panic::catch_unwind::h024d85045c72d3b7
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:359:14
82: 0x562b213a3ee4 - std::thread::Builder::spawn_unchecked_::{{closure}}::h79b2feec76275a8c
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:557:30
83: 0x562b213c4a5f - core::ops::function::FnOnce::call_once{{vtable.shim}}::h651e14205e05c5b4
at /home/allypost/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
84: 0x562b2145692b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he4962534b56a5929
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/alloc/src/boxed.rs:1966:9
85: 0x562b2145692b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h95af12d5a868b9d0
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/alloc/src/boxed.rs:1966:9
86: 0x562b2145692b - std::sys::pal::unix::thread::Thread::new::thread_start::h1822d22fde68314f
at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/pal/unix/thread.rs:97:17
87: 0x7f472fda17eb - <unknown>
88: 0x7f472fe2518c - <unknown>
89: 0x0 - <unknown>
There is an effort to fix it in #2118, but I've not tested whether it mitigates this issue