snapview / tokio-tungstenite

Future-based Tungstenite for Tokio. Lightweight stream-based WebSocket implementation
MIT License
1.88k stars 236 forks source link

Websocket missing some ping messages. #333

Closed ababo closed 6 months ago

ababo commented 6 months ago

I use this crate as a server (being dependency of Axum) and as a client. My process receives an audio stream, decodes it on-the-fly and sends PCM to another process that returns back some JSON data (with much lower rate).

The problem is that I receive websocket disconnects on a regular basis due to ping timeouts (for both client and server ends). Both client and server websockets are read and written to in separate async tasks, the process is never stuck on CPU load (its utilisation never exceeds 0.2%). Some of the ping messages are received (and logged) but it looks like majority of them are just lost. The data messages are sent and received properly.

I know it's hard to judge not having the code, but maybe you could give me your thoughts or advice? Thanks.

agalakhov commented 6 months ago

Do not expect every ping message to pass through. Only the last one matters.

ababo commented 6 months ago

Thank you for the response. I think I understand what might happen. When the socket is loaded with big amount of data (which is consumed with considerably lower rate) and later a ping message is sent. So it will certainly be timed out when properly processed. Closing.