Skip to content

Commit 1eb443e

Browse files
committed
When closing a channels subscription, correctly await for the unsubscribes
1 parent 7879f32 commit 1eb443e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

graphql_ws/django/subscriptions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
from inspect import isawaitable
23
from graphene_django.settings import graphene_settings
34
from graphql.execution.executors.asyncio import AsyncioExecutor
@@ -79,8 +80,12 @@ async def on_start(self, connection_context, op_id, params):
7980
await self.on_operation_complete(connection_context, op_id)
8081

8182
async def on_close(self, connection_context):
82-
for op_id in connection_context.operations:
83+
unsubscribes = [
8384
self.unsubscribe(connection_context, op_id)
85+
for op_id in connection_context.operations
86+
]
87+
if unsubscribes:
88+
await asyncio.wait(unsubscribes)
8489

8590
async def on_stop(self, connection_context, op_id):
8691
await self.unsubscribe(connection_context, op_id)

0 commit comments

Comments
 (0)