Skip to content

Commit 33449bb

Browse files
committed
fix(server): downgrade expected connection teardown errors to debug
h2 connection errors during sandbox deletion are expected — the supervisor gRPC stream is torn down when the sandbox is removed. Downgrade these from ERROR/WARN to DEBUG so they don't pollute gateway logs during normal operations. Signed-off-by: Russell Bryant <[email protected]>
1 parent 6deb1f0 commit 33449bb

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

‎crates/openshell-server/src/grpc/sandbox.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use tokio::net::{TcpListener, TcpStream};
3232
use tokio::sync::mpsc;
3333
use tokio_stream::wrappers::ReceiverStream;
3434
use tonic::{Request, Response, Status};
35-
use tracing::{info, warn};
35+
use tracing::{debug, info, warn};
3636

3737
use russh::ChannelMsg;
3838
use russh::client::AuthResult;
@@ -1001,7 +1001,7 @@ async fn bridge_forward_tcp_stream(
10011001
}
10021002
Ok(None) => break,
10031003
Err(err) => {
1004-
warn!(sandbox_id = %sandbox_id_in, channel_id = %channel_id_in, error = %err, "ForwardTcp: inbound stream failed");
1004+
debug!(sandbox_id = %sandbox_id_in, channel_id = %channel_id_in, error = %err, "ForwardTcp: inbound stream ended");
10051005
break;
10061006
}
10071007
}

‎crates/openshell-server/src/lib.rs‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ fn is_benign_tls_handshake_failure(error: &std::io::Error) -> bool {
111111
)
112112
}
113113

114+
fn is_benign_connection_close(error: &(dyn std::error::Error + 'static)) -> bool {
115+
let msg = error.to_string();
116+
msg.contains("connection closed")
117+
|| msg.contains("connection reset")
118+
|| msg.contains("connection error")
119+
|| msg.contains("error reading a body from connection")
120+
|| msg.contains("broken pipe")
121+
}
122+
114123
impl ServerState {
115124
/// Create new server state.
116125
#[must_use]
@@ -475,7 +484,11 @@ fn spawn_gateway_connection(
475484
) =>
476485
{
477486
if let Err(e) = service.serve_service_http(stream).await {
478-
error!(error = %e, client = %addr, listen = %listen_addr, "Plaintext service HTTP connection error");
487+
if is_benign_connection_close(e.as_ref()) {
488+
debug!(error = %e, client = %addr, listen = %listen_addr, "Plaintext service HTTP connection closed");
489+
} else {
490+
error!(error = %e, client = %addr, listen = %listen_addr, "Plaintext service HTTP connection error");
491+
}
479492
}
480493
}
481494
Ok(ConnectionProtocol::PlainHttp) => {
@@ -485,7 +498,11 @@ fn spawn_gateway_connection(
485498
match acceptor.inner().accept(stream).await {
486499
Ok(tls_stream) => {
487500
if let Err(e) = service.serve(tls_stream).await {
488-
error!(error = %e, client = %addr, "Connection error");
501+
if is_benign_connection_close(e.as_ref()) {
502+
debug!(error = %e, client = %addr, "Connection closed");
503+
} else {
504+
error!(error = %e, client = %addr, "Connection error");
505+
}
489506
}
490507
}
491508
Err(e) => {
@@ -505,7 +522,11 @@ fn spawn_gateway_connection(
505522
} else {
506523
tokio::spawn(async move {
507524
if let Err(e) = service.serve(stream).await {
508-
error!(error = %e, client = %addr, "Connection error");
525+
if is_benign_connection_close(e.as_ref()) {
526+
debug!(error = %e, client = %addr, "Connection closed");
527+
} else {
528+
error!(error = %e, client = %addr, "Connection error");
529+
}
509530
}
510531
});
511532
}

0 commit comments

Comments
 (0)