Skip to content

Commit faea9cf

Browse files
committed
Django Channels connection closed fix
Channels can't tell if the socket is closed since different engines can be used, so explicitly set our own closed prop to work with.
1 parent d7689b7 commit faea9cf

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

graphql_ws/django/consumers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ async def connect(self):
3434

3535
async def disconnect(self, code):
3636
if self.connection_context:
37+
self.connection_context.closed = True
3738
await subscription_server.on_close(self.connection_context)
3839

3940
async def receive_json(self, content):

graphql_ws/django/subscriptions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111

1212
class ChannelsConnectionContext(BaseConnectionContext):
13+
def __init__(self, *args, **kwargs):
14+
super(ChannelsConnectionContext, self).__init__(*args, **kwargs)
15+
self.closed = False
16+
1317
async def send(self, data):
1418
if self.closed:
1519
return
1620
await self.ws.send_json(data)
1721

18-
@property
19-
def closed(self):
20-
return self.ws.closed
21-
2222
async def close(self, code):
2323
await self.ws.close(code=code)
2424

0 commit comments

Comments
 (0)