Skip to content

Commit

Permalink
fix(base): connections for inspector sessions should be upgradeable t…
Browse files Browse the repository at this point in the history
…o the websocket (#399)
  • Loading branch information
nyannyacha authored Aug 23, 2024
1 parent 14f3f92 commit 53061f6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions crates/base/src/inspector_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 53061f6

Please sign in to comment.