-
Notifications
You must be signed in to change notification settings - Fork 197
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
fix: Make sure the Connection.disconnect gets called before the loop is closed #329
Conversation
Thanks for the report. Looks ≈right but let me have a play. How might we test this? 🤔 |
Hi @carltongibson , I tested it in a live project. Without this patch everytime I would instantiate the layer object and call Wi that patch the error don't happen because the connection gets closed in that If you are looking for a unit test, I can try to write one. Don't know how to properly mock this to ensure that the coroutine was never run, but I can give it a try. Note that this fixes the PubSub layer. The core one has a similar issue (#327), which I did not find a good solution for it. The only difference there is that the |
obs. I'm running the beta versions of channels and channels_redis, and while this is not merged I monkey-patched it to force the same behaviour: _original_ensure_redis = RedisSingleShardConnection._ensure_redis
def _ensure_redis(self):
# FIXME: This can be removed once this issue is fixed and released:
# https://github.com/django/channels_redis/issues/328
need_patch_redis = self._redis is None
retval = _original_ensure_redis(self)
if need_patch_redis:
self._redis.close = functools.partial(
self._redis.close,
close_connection_pool=True,
)
return retval
RedisSingleShardConnection._ensure_redis = _ensure_redis It is running in production in a project that relies a lot in the PubSub behaviour for 3 days now and everything is running fine! :) |
Thanks for the follow up @bellini666 As I say sounds correct. Let me have a play. 👍 |
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.
Co-authored-by: Carlton Gibson <[email protected]>
Fix #328