Skip to content

Conversation

IsmoilovMuhriddin
Copy link

Idea for Issue #1119 and #1466

Main problem with why websocket.disconnect not called within daphne.server.Server.application_close_timeout (example: 10 seconds) is:

  • channels.consumer will handle messages(from daphne server and channel layer) one by one
  • if there any message taking too long(send to client, or receive), any incoming messages will be in a queue, and wait to be handled. and if daphne closes the WebSocket consumer, those messages are not closed gracefully, and websocket.disconnect method is not called.

example code to run this

import asyncio
from channels.utils import await_many_dispatch_with_priority
from channels.generic.websocket import AsyncJsonWebsocketConsumer

class CustomWebsocketConsumer(AsyncJsonWebsocketConsumer):
    # uncomment below line 
    # await_many_and_dispatch = await_many_dispatch_with_priority
    
   def send_message(self, message):
       await self.send_json(message)
       await asyncio.sleep(11)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant