#1300

fix(memory): recover stale LRU high-priority weight

Openmjcwants to merge intofrom

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 (or cargo x --fast instead 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
yihong06184mo ago
mjc4mo ago

@yihong0618 yes it was still possible to get into the state mentioned; this refactor should make it recoverable in a safe way

codecov[bot]4mo ago

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests.

Files with missing linesCoverage Δ
foyer-memory/src/eviction/lru.rs97.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.