diff options
author | Luca Casonato <hello@lcas.dev> | 2024-10-17 17:19:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-17 15:19:43 +0000 |
commit | 33ceae4ce5c9f95bde52d5453a6c41488fa36846 (patch) | |
tree | a92e3b27ab3280caf2ac5f66cf61ff0ecf1afd0a | |
parent | 63f6dd355c640016b34484e0f659c00c80256826 (diff) |
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.
-rw-r--r-- | runtime/inspector_server.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/runtime/inspector_server.rs b/runtime/inspector_server.rs index 1f8cd5e71..33b2ab872 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<String>, mut outbound_rx: UnboundedReceiver<InspectorMsg>, ) { + 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; |