-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fixed potential race condition between call_later() and run_forever() #3897
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
base: master
Are you sure you want to change the base?
Conversation
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 potential race condition in the token manager's start() method that could occur when scheduling callbacks before the event loop thread was fully initialized. The fix improves thread-safety by using proper synchronization primitives and thread-safe scheduling methods.
Key Changes:
- Replaced
asyncio.Eventwiththreading.Eventfor cross-thread synchronization to properly coordinate between the main thread and event loop thread - Changed from
loop.call_later()toloop.call_soon_threadsafe()for thread-safe callback scheduling - Simplified the
_renew_token()method signature by removing theinit_eventparameter and handling initialization signaling through a wrapper function
Comments suppressed due to low confidence (1)
redis/auth/token_manager.py:310
- The
_renew_tokenmethod signature has been updated to remove theinit_eventparameter, but the async version_renew_token_asyncat line 310 still retains this parameter. This creates an inconsistency between the two methods. For consistency and maintainability, consider whether_renew_token_asyncshould also be updated to remove theinit_eventparameter if it's no longer needed, or document why the async version still requires it.
):
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
❌ The following Jit checks failed to run:
- secret-detection-trufflehog
#jit_bypass_commit in this PR to bypass, Jit Admin privileges required.
More info in the Jit platform.
Description of change
Please provide a description of the change here.
Pull Request check-list
Please make sure to review and check all of these items:
PR fixes a race condition between
loop.call_later()andloop.run_forever()methods, so the renewal task is scheduled before the event loop is actually running