Should I implement the ping/pong recipe or not? #231
-
The breaking change description of the v5 release has been pretty confusing to me. How do I properly handle connections keep alive now? Doesn’t the OS/browser handle disconnects and forward that state to connections already? So then what does ping/pong achieve apart from increased CPU usage per socket? What does I felt like understanding how to optimally implement it I need to dive deep into the issues and get a solid understanding of ping/pongs. I found this very long thread: #117. One thing that stood out is your explanation of what happens to a WebSocket connection during network downtime: #117 (comment) From this thread it seems to me that you @enisdenjo are opposed to the whole ping-pong approach in the general sense except for a few specific use-cases. e.g. #117 (comment) and
So basically then the OS/browser handle disconnects and forwards that state to connections already? You answered that in So should I implement one of the ping/pong recipes in every WebSocket app or not? Right now I feel like no, since the OS/browser taking care of this should be sufficient for the majority of the apps as per your comments, but your documentation and release notes (i.e. the huge “breaking change” warning) seem to suggest otherwise. I’m having a hard time figuring out if I should implement one of the ping/pong recipes. Tangental question would be whether it would be better to ping from the server as suggested by @andyrichardson in #117 (comment)? ps. It seems I need to have a lot of WS knowledge in order to be able to make this decision, while this library came across as trying to minimize that. Your recipes approach in the README seems focussed around giving everyone options for all their needs, but at the same time it complicates things as users need to figure out which parts are essential and what they do, how they interact with each other, and how to implement them in your lib-specific recipe (mostly relating to "custom retry timeout strategy", "graceful restart", "ping/pong timeout and latency metrics", "manual pings and pongs" and some server recipes conflict with them as well). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Two decisions that influenced the subprotocol level ping/pongs the most are:
It is completely up to you and your use-case whether you want subprotocol ping/pongs. If you aim to transmit mission critical data through the WS connection, then yes, I recommend using the client to send subprotocol level ping/pongs too; or if your backend does not support WS ping/pongs, then yes, I recommend using the server sending subprotocol level ping/pongs to fill in the missing behavior. However, if neither are your use-cases, you're perfectly safe to use the lib out-of-the-box, which is no client pings and server sending a WS level ping every 12 seconds.
The keepAlive is the interval of sending the ping message. Client sends a subprotocol ping message and the server sends a WS level ping message. This is also the reason for the breaking change. If you were to send a subprotocol ping message from a v5 client (using the keepAlive) to a v4 server, the server would terminate the connection immediately. Do note that since the keepAlive option on the client defaults to zero (0), no pings will be sent from the client if not otherwise configured. |
Beta Was this translation helpful? Give feedback.
Two decisions that influenced the subprotocol level ping/pongs the most are:
It is completely up to you and your use-case whether you want subprotocol ping/pongs. If you aim to transmit mission critical data through the WS connection, then yes, I recommend using the client to send subprotocol level ping/pongs too; or if your backend does not support WS ping/pongs, then yes, I recommend using the server sending subprotocol level ping/pongs to fill in the missing behavior. However, if neither are your use-cases, you're perfectly safe to use the lib out-of-the-box, which is no client pings and server sen…