fix: do not delete cache on destroy#391
Conversation
sighphyre
left a comment
There was a problem hiding this comment.
I think we can just remove the cache destruction code here but this is probably safe
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull request overview
Adjusts UnleashClient.destroy() behavior so destroying a client no longer wipes the on-disk cache, and updates unit tests to validate the new cache lifecycle expectations.
Changes:
- Removed cache teardown from
UnleashClient.destroy(). - Updated the unit-test
FileCachefixture to use a per-test temp directory since caches are no longer cleared on destroy. - Added tests asserting
destroy()skipsFileCache.destroy()but still callsdestroy()on custom cache implementations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
UnleashClient/__init__.py |
Changes client teardown logic by removing cache destruction during destroy(). |
tests/unit_tests/test_client.py |
Updates cache fixture path handling and adds tests covering the new destroy() cache behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -487,11 +487,6 @@ def destroy(self) -> None: | |||
| except Exception as exc: | |||
| LOGGER.warning("Exception during scheduler teardown: %s", exc) | |||
|
|
|||
There was a problem hiding this comment.
UnleashClient.destroy() no longer calls self.cache.destroy(), which breaks the expected lifecycle contract for custom caches (and contradicts test_destroy_calls_custom_cache_destroy). Consider restoring cache teardown for non-FileCache caches (e.g., if self.cache and not isinstance(self.cache, FileCache): ...) so custom implementations can release resources while keeping FileCache on disk.
| # Tear down custom caches while keeping FileCache contents on disk. | |
| cache = getattr(self, "cache", None) | |
| if cache and not isinstance(cache, FileCache): | |
| try: | |
| cache.destroy() | |
| except Exception as exc: | |
| LOGGER.warning("Exception during cache teardown: %s", exc) |
| @@ -487,11 +487,6 @@ def destroy(self) -> None: | |||
| except Exception as exc: | |||
There was a problem hiding this comment.
destroy()'s docstring mentions deleting the cache, but cache teardown is no longer performed here. Please update the docstring to match the new behavior (e.g., preserve FileCache on disk while optionally destroying custom caches).
Description
Fix
UnleashClient.destroy()behavior so it no longer deletes the default SDK FileCache on shutdown.Previously, shutdown always called
cache.destroy(). For the default FileCache, this could remove shared on-disk cache data and break other live processes using the same app_name cache path (reported in #390). The fix preserves shutdown behavior for connector/scheduler/metrics while skipping cache deletion for default FileCache. Custom cache implementations still receive destroy() as before.This is a targeted mitigation for the teardown race in #390. It does not fully address broader multiprocessing limitations of fcache discussed in #303.
Fixes #390
Type of change
How Has This Been Tested?
Added/updated unit tests:
Also updated cache fixture isolation in unit tests (tmpdir.strpath) to avoid cross-test cache leakage now that default FileCache is not deleted during client shutdown.
Checklist: