Respond to ping request during non-blocking call #7320
-
Hi, I noted aiohttp websocket client seems only respond to ping request from server in the An demonstration can be found in https://github.com/wenleix/ping-pong . I also tested with websockets Library which can handle ping request during non-blocking call. I am wondering:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It does autoping, but as you've spotted, this only happens inside the Line 288 in edd49b5 I'm not sure if there's really any other way to do it. We can't see the ping message until we read it from the websocket, so how would we know how to respond before this call is made? e.g. We would need to constantly read all messages from the reader prematurely, but if there are a lot of non-ping messages, then this could cause a memory issue, as we now have to store all the pending messages in memory. I'd suggest that you need to rethink your implementation to work within these constraints. e.g. If it's normal to require a long delay between processing each message, then get the server to use a longer timeout. Or, if it's not necessary to process each message sequentially, then start processing in background tasks, so your receive loop can be called a lot more frequently. |
Beta Was this translation helpful? Give feedback.
It does autoping, but as you've spotted, this only happens inside the
.receive()
method:aiohttp/aiohttp/client_ws.py
Line 288 in edd49b5
I'm not sure if there's really any other way to do it. We can't see the ping message until we read it from the websocket, so how would we know how to respond before this call is made? e.g. We would need to constantly read all messages from the reader prematurely, but if there are a lot of non-ping messages, then this could cause a memory issue, as we now have to store all the pending messages in memory.
I'd suggest that you need to rethink your implementation to work within these constraints. e.g. If it's norm…