Skip to content
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

feat: Provide callback function for threaded cache refresh failures #5124

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zabarn
Copy link

@zabarn zabarn commented Mar 6, 2025

What this PR does / why we need it:

The previous implementation of _start_thread_async_refresh was constantly creating new background threads to handle refreshing the cache. This exposed the possibility of running into a Runtime Error: Can't start new thread when attempting to start one, leading to no refresh thread running and causing a stale cache.

We are switching to keeping the same thread running, but using self._stop_event.wait(cache_ttl_seconds) to control when a refresh occurs.

We are also introducing a callback function that is passed through SqlRegistry to CachingRegistry, which allows users to be notified whenever cache refreshes fail, and handle them in whatever way they want.

Which issue(s) this PR fixes:

Misc

@EXPEbdodla

@zabarn zabarn requested a review from a team as a code owner March 6, 2025 16:22
def refresh_loop():
while not self._stop_event.is_set():
try:
time.sleep(cache_ttl_seconds)
Copy link
Contributor

@ntkathole ntkathole Mar 7, 2025

Choose a reason for hiding this comment

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

Suggested change
time.sleep(cache_ttl_seconds)
self._stop_event.wait(cache_ttl_seconds)

@zabarn zabarn requested a review from ntkathole March 10, 2025 14:18
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