What's changed and what's your intention?
Fix LRU high-priority weight recovery when the tracked counter drifts from the intrusive high-priority list.
The overflow path assumed high_priority_weight > high_priority_weight_capacity always implied a non-empty high-priority list, and could panic if the accounting was already stale. This PR repairs stale accounting by recomputing the actual high-priority list weight when recovery is needed, and routes high-priority decrements through a checked helper used by overflow, pop, remove, and acquire paths.
A user of a crate I maintain ran into this scenario in nntp-proxy#73.
Checklist
- I have written the necessary rustdoc comments
- I have added the necessary unit tests and integration tests
- I have passed
cargo x(orcargo x --fastinstead if the old tests are not modified) in my local environment.
cargo x --fast was run; clippy, strict test run, doctests, docs, examples, and cargo-machete passed, then the final legacy license-eye header check step failed. The current license workflow command, hawkeye check, passes.
Activity
4@yihong0618 yes it was still possible to get into the state mentioned; this refactor should make it recoverable in a safe way
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
| Files with missing lines | Coverage Δ | |
|---|---|---|
| foyer-memory/src/eviction/lru.rs | 97.15% <100.00%> (+1.04%) | :arrow_up: |
... and 1 file with indirect coverage changes
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
interesting this kind of releated https://github.com/foyer-rs/foyer/issues/1237 and https://github.com/foyer-rs/foyer/pull/1238