Skip to content

Handle concurrent cache cleanup - #114

Open
samdark wants to merge 3 commits into
fix-gc-filemtime-failurefrom
fix-concurrent-cleanup
Open

samdark wants to merge 3 commits into
fix-gc-filemtime-failurefrom
fix-concurrent-cleanup

Conversation

@samdark

@samdark samdark commented Oct 17, 2026

Copy link
Copy Markdown
Member
Q A
Is bugfix? Yes
New feature? No
Breaks BC? clear() retains cache directories.
Fixed issues Extracted from #110

GC and clear() can throw when another process removes a file first. clear() can also remove a directory needed by a concurrent writer, or fail when a writer fills a directory after it has been scanned.

Treat files already removed as successfully deleted, retain cache directories, and close directory handles even when cleanup fails. Reuse the file-removal handling in delete(), while continuing to report failures when a file remains.

Stacked on #113 to keep each extracted fix in a separate review. This change uses the existing cache format and does not introduce publication locks or atomic writes.

Copilot AI balanced review requested due to automatic review settings October 17, 2026 22:28
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2783439d-3956-4fce-a115-6db7d4da5132

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cleanup can report success after failed removal because a false existence check does not prove absence.

1 open issue
What changed in this PR

Hardens file-cache cleanup against concurrent deletion without changing the cache format or introducing atomic writes.

Changes:

  • Shares file-removal handling across cleanup and delete().
  • Retains cache directories and closes directory handles on failure.
  • Adds cleanup regression tests and documents directory retention.
File Description
tests/​TestCase.php Adds shared cleanup and fixture helpers.
tests/​FileCacheTest.php Uses the shared directory-removal helper.
tests/​CleanupRaceTest.php Tests deletion races, directory retention, and handle closure.
src/​FileCache.php Revises removal handling and preserves directories.
README.md Documents retained cache directories.
CHANGELOG.md Records the cleanup fix.

Review effort: Balanced

Comment thread src/FileCache.php
Comment on lines +481 to +482
if (!file_exists($file)) {
return true;
@codecov

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.78%. Comparing base (179bc58) to head (85387ec).

Additional details and impacted files
@@                      Coverage Diff                       @@
##             fix-gc-filemtime-failure     #114      +/-   ##
==============================================================
+ Coverage                       94.15%   98.78%   +4.63%     
+ Complexity                         71       70       -1     
==============================================================
  Files                               1        1              
  Lines                             171      165       -6     
==============================================================
+ Hits                              161      163       +2     
+ Misses                             10        2       -8     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants