[analyzer] Fix cache size counter drift in EvictingFileByteStore._cleanUpFolder#63127
[analyzer] Fix cache size counter drift in EvictingFileByteStore._cleanUpFolder#63127vedant21-oss wants to merge 1 commit intodart-lang:mainfrom
Conversation
The _cleanUpFolder method was unconditionally decrementing currentSizeBytes
even when file.deleteSync() threw an exception. This allowed the cache
counter to underestimate the actual disk size, potentially allowing the
cache to grow beyond its configured maxSizeBytes limit without triggering
further eviction.
The fix wraps the decrement inside the try block so it only executes
when deletion succeeds.
Test: Two regression tests are added to EvictingFileByteStoreCleanUpTest:
- Verifies successful deletion correctly evicts files.
- Simulates a deletion failure via POSIX permissions and confirms
the counter is NOT decremented when deletion fails.
Fixes: dart-lang#63118
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
@google-cla check |
|
Submitted a fix in #63127 — moves the |
|
Thank you for your contribution! This project uses Gerrit for code reviews. Your pull request has automatically been converted into a code review at: https://dart-review.googlesource.com/c/sdk/+/494021 Please wait for a developer to review your code review at the above link; you can speed up the review if you sign into Gerrit and manually add a reviewer that has recently worked on the relevant code. See CONTRIBUTING.md to learn how to upload changes to Gerrit directly. Additional commits pushed to this PR will update both the PR and the corresponding Gerrit CL. After the review is complete on the CL, your reviewer will merge the CL (automatically closing this PR). |
Problem
EvictingFileByteStore._cleanUpFolderwas decrementingcurrentSizeBytesunconditionally,even when
file.deleteSync()threw an exception:If a file cannot be deleted (e.g. due to a permissions error or a race with another process),
the counter is decremented as though the deletion succeeded. This causes the cache to
underestimate its own size, which can prevent the eviction loop from running again even
though the cache is still over its
maxSizeByteslimit.Fix
Move the decrement inside the
tryblock so it only executes when the deletion actually succeeds:Tests
Two regression tests are added to a new
EvictingFileByteStoreCleanUpTestclass:test_cleanUpFolder_successfulDeletion_decrementsSizeCounter- basic happy-path eviction.test_cleanUpFolder_failedDeletion_doesNotDecrementSizeCounter- simulates a failedchmod 000on the parent directory and verifies that the filesFixes Analyzer cache size accounting drift in EvictingFileByteStore #63118