Skip to content

Comments

fix: do not delete cache on destroy#391

Merged
gastonfournier merged 5 commits intomainfrom
fix/do-not-cache-delete
Feb 13, 2026
Merged

fix: do not delete cache on destroy#391
gastonfournier merged 5 commits intomainfrom
fix/do-not-cache-delete

Conversation

@gastonfournier
Copy link
Contributor

@gastonfournier gastonfournier commented Feb 13, 2026

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Added/updated unit tests:

  • test_destroy_skips_default_file_cache_destroy
  • test_destroy_calls_custom_cache_destroy

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.

  • Unit tests
  • Spec Tests
  • Integration tests / Manual Tests

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link
Member

@sighphyre sighphyre left a comment

Choose a reason for hiding this comment

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

I think we can just remove the cache destruction code here but this is probably safe

@gastonfournier gastonfournier marked this pull request as ready for review February 13, 2026 10:02
Copilot AI review requested due to automatic review settings February 13, 2026 10:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 FileCache fixture to use a per-test temp directory since caches are no longer cleared on destroy.
  • Added tests asserting destroy() skips FileCache.destroy() but still calls destroy() 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)

Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
# 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)

Copilot uses AI. Check for mistakes.
@@ -487,11 +487,6 @@ def destroy(self) -> None:
except Exception as exc:
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

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).

Copilot uses AI. Check for mistakes.
@gastonfournier gastonfournier merged commit 6d1d287 into main Feb 13, 2026
41 checks passed
@gastonfournier gastonfournier deleted the fix/do-not-cache-delete branch February 13, 2026 10:46
@github-project-automation github-project-automation bot moved this from Approved PRs to Done in Issues and PRs Feb 13, 2026
@gastonfournier gastonfournier self-assigned this Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

UnleashClient.destroy() removes shared cache directory across processes

2 participants