From 33ceae4ce5c9f95bde52d5453a6c41488fa36846 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Thu, 17 Oct 2024 17:19:43 +0200 Subject: [PATCH] fix(runtime): send ws ping frames from inspector server (#26352) Every 30 seconds the websocket server will now send a ping frame, so that the TCP socket stays alive. --- runtime/inspector_server.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs index 1f8cd5e714..33b2ab8727 100644 --- a/runtime/inspector_server.rs +++ b/runtime/inspector_server.rs @@ -23,6 +23,7 @@ use deno_core::InspectorSessionProxy; use deno_core::JsRuntime; use fastwebsockets::Frame; use fastwebsockets::OpCode; +use fastwebsockets::Payload; use fastwebsockets::WebSocket; use hyper::body::Bytes; use hyper_util::rt::TokioIo; @@ -33,6 +34,7 @@ use std::pin::pin; use std::process; use std::rc::Rc; use std::thread; +use std::time::Duration; use tokio::net::TcpListener; use tokio::sync::broadcast; use uuid::Uuid; @@ -393,8 +395,13 @@ async fn pump_websocket_messages( inbound_tx: UnboundedSender, mut outbound_rx: UnboundedReceiver, ) { + let mut ticker = tokio::time::interval(Duration::from_secs(30)); + 'pump: loop { tokio::select! { + _ = ticker.tick() => { + let _ = websocket.write_frame(Frame::new(true, OpCode::Ping, None, Payload::Borrowed(&[]))).await; + } Some(msg) = outbound_rx.next() => { let msg = Frame::text(msg.content.into_bytes().into()); let _ = websocket.write_frame(msg).await;