Django Channels AsyncWebSocketConsumer ConnectionClosedError 1005

493 Views Asked by At

I am writing a django channels application and noticed an exception when handling a heartbeat function related to websocket status code which I haven't been able to find any existing issues for. This is in an AsyncWebsocketConsumer backed by redis.

ConnectionClosedError: websockets.exceptions.ConnectionClosedError: received 1005 (no status code [internal]); then sent 1005 (no status code [internal])

    async def receive(self, text_data):
        try:
            if text_data == "healthcheck":
                await self.send(
                    text_data=json.dumps({"type": "healthcheck", "data": self.group_name})
                )
            else:
                logger.info(f"Unsupported WS Event: {text_data}")
                pass
        except:
            logger.exception("Failed to handle message from client")

Also receive this error

RuntimeError: RuntimeError: Unexpected ASGI message 'websocket.send', after sending 'websocket.close'.

My disconnect implementation is

   async def disconnect(self, close_code):
        try:
            # Leave room group
            await self.channel_layer.group_discard(self.group_name, self.channel_name)

            await self.log_request("disconnect")
        except:
            logger.exception("Failed to disconnect user from socket")
0

There are 0 best solutions below