Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expiration bug #137

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,6 @@ impl Db {
.map(|expiration| expiration > when)
.unwrap_or(true);

// Track the expiration.
state.expirations.insert((when, key.clone()));
when
});

Expand All @@ -197,10 +195,17 @@ impl Db {
if let Some(prev) = prev {
if let Some(when) = prev.expires_at {
// clear expiration
state.expirations.remove(&(when, key));
state.expirations.remove(&(when, key.clone()));
}
}

// Track the expiration. If we insert before remove that will cause bug
// when current `(when, key)` equals prev `(when, key)`. Remove then insert
// can avoid this.
if let Some(when) = expires_at {
state.expirations.insert((when, key));
}

// Release the mutex before notifying the background task. This helps
// reduce contention by avoiding the background task waking up only to
// be unable to acquire the mutex due to this function still holding it.
Expand Down
Loading