From 53061f60dbed8265071b014981e749d47dd7495a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=83=A5=EB=83=90=EC=B1=A0?= Date: Fri, 23 Aug 2024 10:00:41 +0900 Subject: [PATCH] fix(base): connections for inspector sessions should be upgradeable to the websocket (#399) --- crates/base/src/inspector_server.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/base/src/inspector_server.rs b/crates/base/src/inspector_server.rs index 12a56eca..d8b183a3 100644 --- a/crates/base/src/inspector_server.rs +++ b/crates/base/src/inspector_server.rs @@ -34,7 +34,6 @@ use hyper::rt::Executor; use hyper_util::rt::TokioIo; use hyper_util::server::conn; use hyper_util::server::graceful::GracefulShutdown; -use log::error; use std::cell::RefCell; use std::collections::HashMap; use std::convert::Infallible; @@ -46,6 +45,7 @@ use std::sync::Arc; use std::thread; use tokio::net::TcpListener; use tokio::sync::watch; +use tracing::error; use uuid::Uuid; #[derive(Debug, Clone, Copy, EnumAsInner)] @@ -226,11 +226,12 @@ fn handle_ws_request( // spawn a task that will wait for websocket connection and then pump messages between // the socket and inspector proxy spawn(async move { - let websocket = if let Ok(w) = fut.await { - w - } else { - eprintln!("Inspector server failed to upgrade to WS connection"); - return; + let websocket = match fut.await { + Ok(w) => w, + Err(err) => { + error!(%err, "inspector server failed to upgrade to ws connection"); + return; + } }; // The 'outbound' channel carries messages sent to the websocket. @@ -371,13 +372,13 @@ async fn server( let (tcp, _) = match listener.accept().await { Ok(conn) => conn, Err(err) => { - error!("accept error: {err}"); + error!(%err); continue; } }; let io = TokioIo::new(tcp); - let conn = conn_builder.serve_connection(io, service_fn.clone()); + let conn = conn_builder.serve_connection_with_upgrades(io, service_fn.clone()); let conn = graceful.watch(conn.into_owned()); executor.execute(async move {