deno icon indicating copy to clipboard operation
deno copied to clipboard

WebSocket: Ping and Pong

Open sinclairzx81 opened this issue 3 years ago • 4 comments

Hi, Would it be possible to include the methods .ping() and .pong() on Deno's Web Socket implementation? It's noted that while browsers do not support sending these control frames, they can be a server side requirement if deploying WebSocket servers behind load balanced environments.

Infrastructure such as AWS's Application / Network Load Balancer (as well as many other load balancers) will automatically terminate idle connections. Applications can mitigate LB termination by periodically sending ping() control frames down to each connected client. Because ping frames are sent out of band from the sockets messaging channel, server applications can keep their connection keep alive logic and application protocol logic separate (with the added benefit of browser Web Sockets not seeing ping control frames at all)

Without this functionality, it does raise quite a few challenges porting existing application protocols to run on Deno. This is due to applications often omitting ping control frames in the applications protocol itself (as it's generally understood that these control frames are already provided as part of the RFC6455 specification)

RFC

https://www.rfc-editor.org/rfc/rfc6455#section-5.5.2 https://www.rfc-editor.org/rfc/rfc6455#section-5.5.3

Rust

https://docs.rs/ws/latest/ws/struct.Frame.html#method.ping https://docs.rs/ws/latest/ws/struct.Frame.html#method.pong

Node

https://github.com/websockets/ws/blob/master/lib/sender.js#L209 https://github.com/websockets/ws/blob/master/lib/sender.js#L252

Would it be possible to include these methods?

sinclairzx81 avatar Aug 09 '22 14:08 sinclairzx81

Closed due to radio silence on this issue.

sinclairzx81 avatar Sep 03 '22 09:09 sinclairzx81

Seems desirable. Reopening.

littledivy avatar Sep 03 '22 10:09 littledivy

Spec issue: https://github.com/whatwg/websockets/issues/10

littledivy avatar Sep 03 '22 10:09 littledivy

I discovered that ping/pong frames are sent automatically thanks to: #13172

But I had to set { idleTimeout: 30 } on the call to Deno.upgradeWebSocket to prevent nginx from killing the connection.

alexgleason avatar May 25 '24 18:05 alexgleason

I am going to close this as we automatically ping-pong now.

lucacasonato avatar Sep 19 '24 10:09 lucacasonato