The wallet test fails with valgrind
spital opened this issue · comments
The problem manifested first in a docker build using Alpine Linux image.
Reproduced on hardware - notebook with Fedora 36 and with the latest commit d0ae3f3 in a Fedora 36 in a VM, 4 cores, 17 GB RAM:
sudo dnf install valgrind rust cargo gcc clang gcc gcc-c++ kernel-headers \
cmake jq wget valgrind pkg-config clang clang-libs llvm-libs \
rust-libudev-devel rust-freetype-rs-devel rust-expat-sys-devel openssl-devel
cargo install cargo-valgrind
cargo valgrind test -vvv --workspace -p darkfi --lib wallet::walletdb::tests::test_walletdb
...
...
Finished test [unoptimized + debuginfo] target(s) in 1m 06s
Running `/home/q/.cargo/bin/cargo-valgrind /home/q/darkfi/target/debug/deps/darkfi-fa21b9bb3c219c37 'wallet::walletdb::tests::test_walletdb'`
running 1 test
test wallet::walletdb::tests::test_walletdb ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 49 filtered out; finished in 42.00s
Error leaked 88 B in 1 block
Info at malloc (vg_replace_malloc.c:381)
at alloc::alloc::alloc (alloc.rs:89)
at <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate (alloc.rs:46)
at hashbrown::raw::inner::alloc::inner::do_alloc (alloc.rs:61)
at hashbrown::raw::inner::RawTableInner<A>::new_uninitialized (mod.rs:1157)
at hashbrown::raw::inner::RawTableInner<A>::fallible_with_capacity (mod.rs:1186)
at hashbrown::raw::inner::RawTableInner<A>::prepare_resize (mod.rs:1396)
at hashbrown::raw::inner::RawTable<T,A>::resize (mod.rs:788)
at hashbrown::raw::inner::RawTable<T,A>::reserve_rehash (mod.rs:693)
at hashbrown::raw::inner::RawTable<T,A>::reserve (mod.rs:646)
at hashbrown::raw::inner::RawTable<T,A>::insert (mod.rs:827)
at indexmap::map::core::IndexMapCore<K,V>::push (core.rs:227)
Error leaked 288 B in 1 block
Info at calloc (vg_replace_malloc.c:1328)
at UnknownInlinedFun (rtld-malloc.h:44)
at allocate_dtv (dl-tls.c:375)
at _dl_allocate_tls (dl-tls.c:634)
at allocate_stack (allocatestack.c:428)
at pthread_create@@GLIBC_2.34 (pthread_create.c:647)
at std::sys::unix::thread::Thread::new
at std::thread::Builder::spawn_unchecked_ (mod.rs:526)
at std::thread::Builder::spawn_unchecked (mod.rs:456)
at std::thread::Builder::spawn (mod.rs:388)
at async_io::driver::UNPARKER::{{closure}} (driver.rs:27)
at core::ops::function::FnOnce::call_once (function.rs:227)
at core::ops::function::FnOnce::call_once (function.rs:227)
at once_cell::sync::Lazy<T,F>::force::{{closure}} (lib.rs:1182)
Error leaked 460 B in 4 blocks
Info at malloc (vg_replace_malloc.c:381)
at alloc::alloc::alloc (alloc.rs:89)
at <hashbrown::raw::inner::alloc::inner::Global as hashbrown::raw::inner::alloc::inner::Allocator>::allocate (alloc.rs:46)
at hashbrown::raw::inner::alloc::inner::do_alloc (alloc.rs:61)
at hashbrown::raw::inner::RawTableInner<A>::new_uninitialized (mod.rs:1157)
at hashbrown::raw::inner::RawTableInner<A>::fallible_with_capacity (mod.rs:1186)
at hashbrown::raw::inner::RawTableInner<A>::prepare_resize (mod.rs:1396)
at hashbrown::raw::inner::RawTable<T,A>::resize (mod.rs:788)
at hashbrown::raw::inner::RawTable<T,A>::reserve_rehash (mod.rs:693)
at hashbrown::raw::inner::RawTable<T,A>::reserve (mod.rs:646)
at hashbrown::raw::inner::RawTable<T,A>::insert (mod.rs:827)
at hashbrown::raw::inner::RawTable<T,A>::insert_entry (mod.rs:865)
Error leaked 768 B in 24 blocks
Info at malloc (vg_replace_malloc.c:381)
at alloc::alloc::alloc (alloc.rs:89)
at alloc::alloc::Global::alloc_impl (alloc.rs:171)
at <alloc::alloc::Global as core::alloc::Allocator>::allocate (alloc.rs:231)
at alloc::alloc::exchange_malloc (alloc.rs:320)
at alloc::sync::Arc<T>::new (sync.rs:346)
at waker_fn::waker_fn (lib.rs:29)
at async_io::driver::block_on (driver.rs:126)
at async_global_executor::reactor::block_on::{{closure}} (reactor.rs:3)
at async_global_executor::reactor::block_on (reactor.rs:12)
at async_global_executor::threading::thread_main_loop::{{closure}}::{{closure}} (threading.rs:95)
at std::thread::local::LocalKey<T>::try_with (local.rs:442)
Error leaked 1.1 kiB in 4 blocks
Info at calloc (vg_replace_malloc.c:1328)
at UnknownInlinedFun (rtld-malloc.h:44)
at allocate_dtv (dl-tls.c:375)
at _dl_allocate_tls (dl-tls.c:634)
at allocate_stack (allocatestack.c:428)
at pthread_create@@GLIBC_2.34 (pthread_create.c:647)
at std::sys::unix::thread::Thread::new
at std::thread::Builder::spawn_unchecked_ (mod.rs:526)
at std::thread::Builder::spawn_unchecked (mod.rs:456)
at std::thread::Builder::spawn (mod.rs:388)
at sqlx_core::sqlite::connection::worker::ConnectionWorker::establish::{{closure}} (worker.rs:86)
at <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll (mod.rs:91)
at sqlx_core::sqlite::connection::SqliteConnection::establish::{{closure}} (mod.rs:71)
at <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll (mod.rs:91)
Error leaked 2.9 kiB in 30 blocks
Info at malloc (vg_replace_malloc.c:381)
at alloc::alloc::alloc (alloc.rs:89)
at alloc::alloc::Global::alloc_impl (alloc.rs:171)
at <alloc::alloc::Global as core::alloc::Allocator>::allocate (alloc.rs:231)
at alloc::raw_vec::RawVec<T,A>::allocate_in (raw_vec.rs:185)
at alloc::raw_vec::RawVec<T,A>::with_capacity_in (raw_vec.rs:132)
at alloc::vec::Vec<T,A>::with_capacity_in (mod.rs:613)
at <T as alloc::slice::hack::ConvertVec>::to_vec (slice.rs:227)
at alloc::slice::hack::to_vec (slice.rs:176)
at alloc::slice::<impl [T]>::to_vec_in (slice.rs:507)
at alloc::slice::<impl [T]>::to_vec (slice.rs:482)
at alloc::slice::<impl alloc::borrow::ToOwned for [T]>::to_owned (slice.rs:858)
Error leaked 4.0 kiB in 1 block
Info at malloc (vg_replace_malloc.c:381)
at sqlite3MemMalloc (sqlite3.c:30290)
at sqlcipher_mem_malloc (sqlite3.c:23893)
at mallocWithAlarm (sqlite3.c:33984)
at sqlite3Malloc (sqlite3.c:34014)
at pcache1Alloc (sqlite3.c:56708)
at sqlite3PageMalloc (sqlite3.c:56852)
at allocateTempSpace (sqlite3.c:73390)
at btreeCursor (sqlite3.c:75153)
at btreeCursorWithLock (sqlite3.c:75196)
at sqlite3BtreeCursor (sqlite3.c:75208)
at sqlite3VdbeExec (sqlite3.c:95885)
Error leaked 5.3 kiB in 23 blocks
Info at malloc (vg_replace_malloc.c:381)
at alloc::alloc::alloc (alloc.rs:89)
at alloc::alloc::Global::alloc_impl (alloc.rs:171)
at <alloc::alloc::Global as core::alloc::Allocator>::allocate (alloc.rs:231)
at hashbrown::raw::alloc::inner::do_alloc (alloc.rs:11)
at hashbrown::raw::RawTableInner<A>::new_uninitialized (mod.rs:1086)
at hashbrown::raw::RawTableInner<A>::fallible_with_capacity (mod.rs:1115)
at hashbrown::raw::RawTable<T,A>::fallible_with_capacity (mod.rs:466)
at hashbrown::raw::RawTable<T,A>::with_capacity_in (mod.rs:487)
at hashbrown::raw::RawTable<T>::with_capacity (mod.rs:417)
at hashbrown::map::HashMap<K,V,S>::with_capacity_and_hasher (map.rs:411)
at std::collections::hash::map::HashMap<K,V,S>::with_capacity_and_hasher (map.rs:308)
Error leaked 6.8 kiB in 24 blocks
Info at calloc (vg_replace_malloc.c:1328)
at UnknownInlinedFun (rtld-malloc.h:44)
at allocate_dtv (dl-tls.c:375)
at _dl_allocate_tls (dl-tls.c:634)
at allocate_stack (allocatestack.c:428)
at pthread_create@@GLIBC_2.34 (pthread_create.c:647)
at std::sys::unix::thread::Thread::new
at std::thread::Builder::spawn_unchecked_ (mod.rs:526)
at std::thread::Builder::spawn_unchecked (mod.rs:456)
at std::thread::Builder::spawn (mod.rs:388)
at async_global_executor::threading::spawn_more_threads::{{closure}} (threading.rs:43)
at <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll (mod.rs:91)
at async_global_executor::init::init::{{closure}} (init.rs:37)
at <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll (mod.rs:91)
Error leaked 21.3 kiB in 5 blocks
Info at malloc (vg_replace_malloc.c:381)
at sqlite3MemMalloc (sqlite3.c:30290)
at sqlcipher_mem_malloc (sqlite3.c:23893)
at mallocWithAlarm (sqlite3.c:33984)
at sqlite3Malloc (sqlite3.c:34014)
at pcache1Alloc (sqlite3.c:56708)
at pcache1AllocPage (sqlite3.c:56805)
at pcache1FetchStage2 (sqlite3.c:57281)
at pcache1FetchNoMutex (sqlite3.c:57385)
at pcache1FetchWithMutex (sqlite3.c:57400)
at pcache1Fetch (sqlite3.c:57423)
at sqlite3PcacheFetch (sqlite3.c:55857)
Summary Leaked 42.9 kiB total
error: test failed, to rerun pass '-p darkfi --lib'
The test still fails.
rustc -V
rustc 1.64.0 (a55dd71d5 2022-09-19)
May be related to the test coredumps in Alpine Linux v3.16 with rust 1.64.
exe=target/release/deps/darkfi-96fc625923ef093a
tests='wallet::walletdb::tests::test_walletdb zk::circuit::burn_contract::tests::burn_circuit_assert zk::circuit::mint_contract::tests::mint_circuit_assert zk::gadget::arithmetic::tests::arithmetic_circuit_assert zk::gadget::less_than::tests::less_than_64 zk::gadget::native_range_check::tests::native_range_check_128 zk::gadget::native_range_check::tests::native_range_check_253 zk::gadget::native_range_check::tests::native_range_check_64'
for test in $tests; do $exe --test --exact $test;done
Expected: ok
Actual: Segmentation fault (core dumped)
I was looking at this, and it seems to be internally related to SQLite. We have plans in the future to migrate to our own internal Db. This is just used during the bootstrapping phase and it's likely not to be a major show stopper to getting darkfi online. But yeah we will slowly deprecate this portion of the code, and develop a new replacement module for WalletDb.