Closed feymartynov closed 6 months ago
Thanks a lot! I must have made a rudimentary mistake in the linked list management code. I'll fix it as soon as possible, hopefully by the end of this week.
Fortunately, not a complicated problem, so I can upload 2.0.10 within a couple of hours.
This issue is fixed in SCC 2.0.10.
Thanks again for finding out this bug!
Thanks for the quick fix. The original example now passes but I found a more complex one which still panics with the same backtrace:
use std::sync::Arc;
use std::time::{Duration, Instant};
use scc::HashCache;
const CAPACITY: usize = 4_194_304;
fn main() {
let start = Instant::now();
let hc = Arc::new(HashCache::<usize, u64>::with_capacity(CAPACITY, CAPACITY));
let hc_clone = hc.clone();
std::thread::spawn(move || loop {
for key in 0..CAPACITY {
let _ = hc.get(&key).unwrap_or_else(|| {
hc.entry(key)
.or_put_with(|| {
Instant::now()
.checked_duration_since(start)
.unwrap()
.as_secs()
})
.1
});
}
});
std::thread::spawn(move || loop {
let deadline = Instant::now()
.checked_duration_since(start)
.unwrap()
.as_secs()
.saturating_sub(Duration::from_secs(1).as_secs());
hc_clone.retain(|_, v| deadline <= *v);
})
.join()
.unwrap();
}
Thanks again, I'll look into the remaining issue tomorrow!
-> Now the issue seems to be with put
; if my assumption is right, it will take more time to fix than the first issue.
-> In addition to this, more test cases are definitely needed.
Identified the issue, and fixed it.
SCC 2.0.11 will include the fix.
-> I figured that the HashCache code is not quite optimal, so created #122.
Hello! I try to use
scc::HashCache
to build a rate limiter for a proxy server. There's a number of workers which get and put user rate data into the structure and a background job which periodically cleans up obsolete data alongside with LRU.However I got panics and made an investigation which lead me to the following minimal example which reproduces the panic:
Debug run fails on an assertion:
Release build don't always fail but often gives this:
Rust version: 1.75.0.