-
Notifications
You must be signed in to change notification settings - Fork 72
Fix FSEvents RuntimeError on concurrent cache access #321
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
Conversation
- Catch RuntimeError when observer.schedule() fails with "Cannot add watch" - Fall back to polling mode when this error occurs (common on macOS FSEvents) - Add tests for RuntimeError handling in wait_on_entry_calc - Ensures graceful degradation when multiple observers watch same path Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #321 +/- ##
=======================================
Coverage 98.40% 98.41%
=======================================
Files 11 11
Lines 1005 1010 +5
Branches 119 120 +1
=======================================
+ Hits 989 994 +5
Misses 9 9
Partials 7 7
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a RuntimeError that occurs on macOS when FSEvents is unable to add a watch due to concurrent cache directory monitoring. The fix provides graceful degradation by falling back to polling when the FSEvents observer cannot be scheduled.
Changes:
- Added RuntimeError exception handling in
wait_on_entry_calc()to catch "Cannot add watch" errors from FSEvents - Falls back to polling mechanism when FSEvents rejects the watch, mirroring the existing inotify limit handling pattern
- Added comprehensive test coverage for both the fallback scenario and proper re-raising of unrelated RuntimeErrors
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/cachier/cores/pickle.py | Added RuntimeError catch block with string matching for FSEvents "Cannot add watch" error, includes debug logging and fallback to polling |
| tests/test_pickle_core.py | Added two test cases: one verifying polling fallback on FSEvents error, one ensuring other RuntimeErrors propagate correctly |
On macOS, FSEvents throws
RuntimeError: Cannot add watchwhen multiple threads/processes attempt to monitor the same cache directory concurrently. This occurs inwait_on_entry_calc()when multiple callers create observers for the same path.Changes
Error Handling in
src/cachier/cores/pickle.py:RuntimeErrorcatch for "Cannot add watch" inwait_on_entry_calc()_wait_with_polling()when FSEvents rejects the watchTest Coverage in
tests/test_pickle_core.py:test_wait_on_entry_calc_runtime_error_watch_scheduled- verifies polling fallbacktest_wait_on_entry_calc_other_runtime_error- ensures other RuntimeErrors propagateExample Scenario
The fix provides graceful degradation on macOS FSEvents while maintaining full functionality through the existing polling mechanism.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.