rust-rocksdb / rust-rocksdb

rust wrapper for rocksdb
Apache License 2.0
1.78k stars 711 forks source link

TransactionDB `open_default` panic #881

Open fansehep opened 2 months ago

fansehep commented 2 months ago

This demo in my laptop, it will panic.

use rocksdb::TransactionDB;

fn main() {
    let _db: TransactionDB = rocksdb::TransactionDB::open_default("./rocks_data").unwrap();

    println!("Hello, world!");
}

output:

thread 'main' panicked at library/core/src/panicking.rs:220:5:
unsafe precondition(s) violated: ptr::copy_nonoverlapping requires that both pointer arguments are aligned and non-null and the specified memory ranges do not overlap
stack backtrace:
   0: rust_begin_unwind
             at /rustc/3a36386dc1075018dc7ca2640a2656adb31a61fe/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/3a36386dc1075018dc7ca2640a2656adb31a61fe/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/3a36386dc1075018dc7ca2640a2656adb31a61fe/library/core/src/panicking.rs:120:5
   ...

I'm confused about this.

fansehep commented 2 months ago

I switch the rustc to stable, it will be ok. :(

peacess commented 2 months ago

i have the same case, just call open_default, and then panic.

std::ptr::copy_nonoverlapping(ptr, vec.as_mut_ptr(), cnt); the ptr parameter is NULL, so it will panic

ravlio commented 1 month ago

Same, but only during tests

miladamery commented 1 month ago

I Have the same issue

unsafe precondition(s) violated: ptr::copy_nonoverlapping requires that both pointer arguments 

are aligned and non-null and the specified memory ranges do not overlap

any idea why this happens?

pragmaxim commented 1 month ago

It only happens with

rustc 1.78.0 AND 1.80.0-nightly

but not

rustc 1.75.0

Testing with :

rocksdb = "0.22.0" AND 0.21.0
let mut opts = Options::default();
opts.create_if_missing(true);
let txn_db_opts = TransactionDBOptions::default();
let db = TransactionDB::open(&opts, &txn_db_opts, db_path).unwrap();
   0: rust_begin_unwind                                                                                                                                                                                                                        
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5                                                                                                                                             
   1: core::panicking::panic_nounwind_fmt::runtime                                                                                                                                                                                             
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:110:18                                                                                                                                           
   2: core::panicking::panic_nounwind_fmt                                                                                                                                                                                                      
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:123:9                                                                                                                                            
   3: core::panicking::panic_nounwind                                                                                                                                                                                                          
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:156:5
   4: core::intrinsics::copy_nonoverlapping::precondition_check
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/intrinsics.rs:2799:21
   5: core::intrinsics::copy_nonoverlapping
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/intrinsics.rs:2969:5
   6: rocksdb::transactions::transaction_db::TransactionDB<T>::open_cf_descriptors_internal
             at /home/lisak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocksdb-0.22.0/src/transactions/transaction_db.rs:303:13
   7: rocksdb::transactions::transaction_db::TransactionDB<T>::open_cf
             at /home/lisak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocksdb-0.22.0/src/transactions/transaction_db.rs:200:9
   8: rocksdb::transactions::transaction_db::TransactionDB<T>::open
             at /home/lisak/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rocksdb-0.22.0/src/transactions/transaction_db.rs:179:9
   9: index_btc::merkle::AddressIndexer::new
mpartel commented 1 month ago

Workaround:

rocksdb = { git = "https://github.com/rust-rocksdb/rust-rocksdb", rev = "1cf906dc4087f06631820f13855e6b27bd21b972" }

The other commits between 0.22.0 and that one are very minor.

peacess commented 1 month ago

panic in 1.79.0

zilong-dai commented 3 weeks ago

release version may not panic

zilong-dai commented 2 weeks ago

This commit on master branch have fixed this issue https://github.com/rust-rocksdb/rust-rocksdb/commit/1cf906dc4087f06631820f13855e6b27bd21b972