Folks, I need your help again.
I have a problem I am not able to understand and maybe I am just overlooking something.
Overall I get a segmentation fault from std::sync::mpsc::Sender<T>::send()
that you can traceback below.
Thread 1 "redis-server" received signal SIGSEGV, Segmentation fault.
0x00007ffff4a36728 in core::sync::atomic::atomic_compare_exchange ()
at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/sync/atomic.rs:2182
2182 /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/sync/atomic.rs: No such file or directory.
(gdb) bt
#0 0x00007ffff4a36728 in core::sync::atomic::atomic_compare_exchange ()
at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/sync/atomic.rs:2182
#1 core::sync::atomic::AtomicBool::compare_exchange ()
at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/sync/atomic.rs:559
#2 core::sync::atomic::AtomicBool::compare_and_swap ()
at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libcore/sync/atomic.rs:502
#3 std::sync::mpsc::blocking::SignalToken::signal () at src/libstd/sync/mpsc/blocking.rs:46
#4 0x00007ffff47744fc in std::sync::mpsc::Sender<T>::send (self=0x7fffffffd2d8, t=...)
at /rustc/eae3437dfe991621e8afdc82734f4a172d7ddf9b/src/libstd/sync/mpsc/mod.rs:830
#5 0x00007ffff47867df in redis_sql::commands::Exec (ctx=0x7fffffffd750, argv=0x7ffff6c28f18, argc=3)
at src/commands.rs:350
#6 0x000000000049f9cf in RedisModuleCommandDispatcher (c=<optimized out>) at module.c:509
#7 0x000000000042fc6f in call (c=c@entry=0x7ffff6d0dcc0, flags=flags@entry=15) at server.c:2437
#8 0x0000000000430337 in processCommand (c=0x7ffff6d0dcc0) at server.c:2729
#9 0x00000000004406a5 in processInputBuffer (c=0x7ffff6d0dcc0) at networking.c:1446
#10 0x00000000004298fd in aeProcessEvents (eventLoop=eventLoop@entry=0x7ffff6c300a0, flags=flags@entry=11)
at ae.c:443
#11 0x0000000000429b2b in aeMain (eventLoop=0x7ffff6c300a0) at ae.c:501
#12 0x00000000004266de in main (argc=<optimized out>, argv=0x7fffffffda78) at server.c:4197
The code is quite complex and I wasn't able to isolate the issue in something smaller, but maybe some of you already saw something similar.
pub struct RedisDBKey {
key: *mut rm::ffi::RedisModuleKey,
// we don't want the field below to be dropped
pub dbkey: std::mem::ManuallyDrop<DBKey>,
}
impl Drop for RedisDBKey {
fn drop(&mut self) {
// special behaviour for the key field
debug!("***Closing the key.***");
unsafe {
rm::ffi::RedisModule_CloseKey.unwrap()(self.key);
}
}
}
impl RedisDBKey {
pub fn new(context: &Context, name: &str) -> Result<Self, i32> {
....
// we get a pointer from external library and then we .read() it
let db_ptr = unsafe {
rm::ffi::RedisModule_ModuleTypeGetValue.unwrap()(key)
as *mut DBKey
};
let dbkey =
std::mem::ManuallyDrop::new(unsafe { db_ptr.read() });
Ok(RedisDBKey { key, dbkey })
.....
}
}
....
let db = match RedisDBKey::new(&context, argvector[1]).unwrap()
let ch = &db.dbkey.tx;
match ch.send(cmd) // crash here
I don't understand if I am not respecting some invariant of channels or what else I am doing wrong.
Do you guys have any idea?