-
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
Connection.disconnect got Future attached to a different loop when sending a message in a django ASGI view #327
Comments
Does 4.0.0b2 also behave the same way? It has a few changes/fixes/improvements from b1 that look familiar to the above. |
Hi @bbrowning918 , O sorry, that issue is in b2 actually (I got confused with |
Thanks for the report @bellini666. It's a cleanup warning... there's task not finished when the event loop shuts down. (You're running this under WSGI?) A minimal reproduction would be handy. |
The trick will be to give the connection a chance to close before finishing. |
Hi @carltongibson , I'm running this under ASGI, it works both with I mentioned this in this PR which fixes a similar issue for PubSub layer. In there the issue is really giving it a chance to close, but in this case it is strange that the loops are indeed not the same. I did |
@bellini666 — it would be handy if you could put together an absolutely minimal Django project that triggers this. (Single view etc.) Different loop... — I need to see how/where you're creating the channel layer. 🤔 |
Hi @carltongibson , The test case you wrote for #329 should also trigger this when using the core layer instead of the pubsub If not, I can try to create a minimal example. But I found both issues using the exact same code, the difference is that the core layer would give this traceback and the PubSub one would give that warning from that other issue I opened |
@bellini666 yes, it would likely work 🤔 I didn't try it yet, for want of a fix. My plan is to potter on it after the Channels release, but if you have ideas let me know. Thanks! |
While I was looking around with a similar issue to bellini I think I found a possible culprit for the error message? I was tracing down the future error message and it seems like it all comes back to the block in the op: I monkey patched it to the following and that fixed the error message: def __del__(self):
try:
if self.is_connected:
loop = asyncio.get_running_loop()
coro = self.disconnect()
if loop.is_running():
# original method call: loop.create_task(coro)
loop.run_until_complete(coro)
else:
loop.run_until_complete(coro)
except Exception:
pass The error that caused this seems kind of silly as I was following the future I found this in def create_task(self, coro, *, name=None):
raise NotImplementedError *it's probably not related to this followed the methods wrong. Not sure if bellini wants to try monkey patching |
Doing some more testing that monkey patch seems to have stopped those |
Just upgraded my project to 4.0.0b1 (with also updating channels/daphne/etc) and started to get this error after doing a
layer.group_send
inside a django ASGI view (i.e. not a channels consumer):It seems that this is scheduled from the
Connection.__del__
method.obs. This does not break the view itself, but I see that message everytime. e.g. I have a post_save signal that will do a
group_send
to inform some listeners that the object has changes. When saving the object inside django admin or even in another view thegroup_send
is executed correctly, the message is received by the listeners correctly and the view returns the response correctly, but I always see that traceback in my terminalThe text was updated successfully, but these errors were encountered: