Open
Description
Hi! We noticed a segfault from moka in our application. Here's a backtrace:
1: moka::common::concurrent::entry_info::EntryInfo<K>::expiration_time
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/common/concurrent/entry_info.rs:121:9
moka::common::timer_wheel::TimerWheel<K>::schedule_existing_node
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/common/timer_wheel.rs:235:49
2: moka::common::timer_wheel::TimerWheel<K>::reschedule
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/common/timer_wheel.rs:258:9
moka::sync_base::base_cache::Inner<K,V,S>::update_timer_wheel
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/sync_base/base_cache.rs:1753:42
3: moka::sync_base::base_cache::Inner<K,V,S>::apply_reads
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/sync_base/base_cache.rs:1392:25
moka::sync_base::base_cache::Inner<K,V,S>::do_run_pending_tasks
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/sync_base/base_cache.rs:1207:21
4: <moka::sync_base::base_cache::Inner<K,V,S> as moka::common::concurrent::housekeeper::InnerSync>::run_pending_tasks
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/sync_base/base_cache.rs:1163:9
moka::common::concurrent::housekeeper::Housekeeper::do_run_pending_tasks
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/common/concurrent/housekeeper.rs:125:29
moka::common::concurrent::housekeeper::Housekeeper::run_pending_tasks
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/common/concurrent/housekeeper.rs:107:9
5: moka::sync::cache::Cache<K,V,S>::run_pending_tasks
at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/moka-0.12.10/src/sync/cache.rs:1784:13
My attempt to reproduce it does produce a segfault and/or hits an unreachable!
, although I'm not sure if it's 100% related to the above backtrace from our actual app
use rand::Rng;
use std::time::Duration;
use moka::sync::{Cache, CacheBuilder};
use moka::Expiry;
struct ExpireFromCreate(Duration);
impl<T, V> Expiry<T, V> for ExpireFromCreate {
fn expire_after_create(
&self,
_key: &T,
_value: &V,
_created_at: std::time::Instant,
) -> Option<Duration> {
Some(self.0)
}
fn expire_after_read(
&self,
_key: &T,
_value: &V,
_read_at: std::time::Instant,
_duration_until_expiry: Option<Duration>,
_last_modified_at: std::time::Instant,
) -> Option<Duration> {
None
}
fn expire_after_update(
&self,
_key: &T,
_value: &V,
_updated_at: std::time::Instant,
_duration_until_expiry: Option<Duration>,
) -> Option<Duration> {
None
}
}
fn main() {
let cache: Cache<u64, u64> = CacheBuilder::new(1000)
.name("my-cache")
.expire_after(ExpireFromCreate(Duration::from_secs(1)))
.eviction_listener(|key, value, reason| {
if reason == moka::notification::RemovalCause::Expired {
eprint!("{} {} {:?}", key, value, reason)
}
})
.build();
let cache_ = cache.clone();
std::thread::spawn(move || {
let mut rng = rand::thread_rng();
for _ in 0..1000 {
std::thread::sleep(Duration::from_millis(100));
let keys_count = 10;
let keys: Vec<u64> = (0..keys_count).map(|_| rng.gen_range(0..1000)).collect();
let value: u64 = 1312;
let cache = cache.clone();
std::thread::spawn(move || {
keys.iter().for_each(move |k| {
cache.entry(*k).and_upsert_with(move |entry| {
if let Some(entry) = entry {
let mut v = entry.into_value();
v += value;
v
} else {
value
}
});
});
});
}
});
loop {
cache_.run_pending_tasks();
std::thread::sleep(Duration::from_secs(1));
}
}
some backtraces from the code above:
thread '<unnamed>' panicked at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/common/timer_wheel.rs:283:13:
internal error: entered unreachable code
stack backtrace:
0: rust_begin_unwind
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/std/src/panicking.rs:665:5
1: core::panicking::panic_fmt
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/core/src/panicking.rs:76:14
2: core::panicking::panic
at /rustc/9fc6b43126469e3858e2fe86cafb4f0fd5068869/library/core/src/panicking.rs:148:5
3: moka::common::timer_wheel::TimerWheel<K>::unlink_timer
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/common/timer_wheel.rs:283:13
4: moka::common::timer_wheel::TimerWheel<K>::deschedule
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/common/timer_wheel.rs:265:13
5: moka::sync_base::base_cache::Inner<K,V,S>::update_timer_wheel
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync_base/base_cache.rs:1766:17
6: moka::sync_base::base_cache::Inner<K,V,S>::apply_reads
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync_base/base_cache.rs:1392:25
7: moka::sync_base::base_cache::Inner<K,V,S>::do_run_pending_tasks
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync_base/base_cache.rs:1207:21
8: <moka::sync_base::base_cache::Inner<K,V,S> as moka::common::concurrent::housekeeper::InnerSync>::run_pending_tasks
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync_base/base_cache.rs:1163:9
9: moka::common::concurrent::housekeeper::Housekeeper::do_run_pending_tasks
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/common/concurrent/housekeeper.rs:125:29
10: moka::common::concurrent::housekeeper::Housekeeper::try_run_pending_tasks
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/common/concurrent/housekeeper.rs:112:13
11: moka::sync_base::base_cache::BaseCache<K,V,S>::apply_reads_if_needed
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync_base/base_cache.rs:611:17
12: moka::sync_base::base_cache::BaseCache<K,V,S>::record_read_op
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync_base/base_cache.rs:479:9
13: moka::sync_base::base_cache::BaseCache<K,V,S>::get_with_hash_and_ignore_if::{{closure}}
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync_base/base_cache.rs:246:13
14: moka::sync_base::base_cache::BaseCache<K,V,S>::do_get_with_hash
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync_base/base_cache.rs:372:13
15: moka::sync_base::base_cache::BaseCache<K,V,S>::get_with_hash_and_ignore_if
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync_base/base_cache.rs:249:9
16: moka::sync::value_initializer::ValueInitializer<K,V,S>::try_compute
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync/value_initializer.rs:229:27
17: moka::sync::cache::Cache<K,V,S>::upsert_with_hash_and_fun
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync/cache.rs:1553:15
18: moka::sync::entry_selector::OwnedKeyEntrySelector<K,V,S>::and_upsert_with
at /home/ethompson/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.10/src/sync/entry_selector.rs:293:9
19: moka_test::main::{{closure}}::{{closure}}::{{closure}}
at ./src/main.rs:63:21
20: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::for_each
at /home/ethompson/.rustup/toolchains/1.84.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/iter/macros.rs:254:21
21: moka_test::main::{{closure}}::{{closure}}
at ./src/main.rs:62:17
Metadata
Metadata
Assignees
Labels
No labels