Hold references to ClusterNode disconnect task#3826
Hold references to ClusterNode disconnect task#3826petyaslavova merged 3 commits intoredis:masterfrom
Conversation
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
|
Hi @rhoboro, thank you for your contribution! We will review your change soon. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a potential bug where background tasks created for disconnecting removed cluster nodes could be prematurely garbage collected due to Python's asyncio only keeping weak references to tasks. The fix holds strong references to these tasks in a set, ensuring they complete execution.
Changes:
- Added
_background_tasksset to track disconnection tasks - Updated
set_nodesto store task references and automatically remove them upon completion
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
* Hold references to ClusterNode disconnect task * Fix linters --------- Co-authored-by: petyaslavova <petya.slavova@redis.com>
Thank you for this awesome library! I've been a long-time user of this project ✨
Pull Request check-list
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Description of change
I found a potential bug and have fixed it.
This fix aligns with the recommendations in the official documentation linked below, as I have personally encountered unintended task loss due to this issue in the past.
https://docs.python.org/3.13/library/asyncio-task.html#asyncio.create_task