Search code examples
pythonwebsocketpython-asynciotornado

asyncio.sleep causes Tornado websocket to disconnect


We've set

WEBSOCKET_PING_INTERVAL_SEC = 2
WEBSOCKET_PING_TIMEOUT_SEC = 4

(the parameters we pass to Tornado's websocket handler.)

Now, whenever we do a long ( > 6) asyncio.sleep in our code, our websocket disconnects, while regular time.sleep does not disconnect it. Obviously, it seems the websocket ping interval does not play nice with asyncio.sleep.

What should we change to fix this? (Assuming we still need the total of 6 seconds to detect disconnections.)


Solution

  • It seems that frame processing in Tornado is done sequentially, which means that pings will not be handled in time if a different message is being handled for a very long time.

    We've opened an issue in the Tornado GitHub repo here.