Skip to content

Commit 1d988d9

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.
1 parent 113ecb8 commit 1d988d9

2 files changed

Lines changed: 21 additions & 4 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;
@@ -1003,7 +1003,7 @@ async fn bridge_forward_tcp_stream(
10031003
}
10041004
Ok(None) => break,
10051005
Err(err) => {
1006-
warn!(sandbox_id = %sandbox_id_in, channel_id = %channel_id_in, error = %err, "ForwardTcp: inbound stream failed");
1006+
debug!(sandbox_id = %sandbox_id_in, channel_id = %channel_id_in, error = %err, "ForwardTcp: inbound stream ended");
10071007
break;
10081008
}
10091009
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ fn is_benign_tls_handshake_failure(error: &std::io::Error) -> bool {
110110
)
111111
}
112112

113+
fn is_benign_connection_close(error: &(dyn std::error::Error + 'static)) -> bool {
114+
let msg = error.to_string();
115+
msg.contains("connection closed")
116+
|| msg.contains("connection reset")
117+
|| msg.contains("connection error")
118+
|| msg.contains("error reading a body from connection")
119+
|| msg.contains("broken pipe")
120+
}
121+
113122
impl ServerState {
114123
/// Create new server state.
115124
#[must_use]
@@ -399,7 +408,11 @@ fn spawn_gateway_connection(
399408
match acceptor.inner().accept(stream).await {
400409
Ok(tls_stream) => {
401410
if let Err(e) = service.serve(tls_stream).await {
402-
error!(error = %e, client = %addr, "Connection error");
411+
if is_benign_connection_close(e.as_ref()) {
412+
debug!(error = %e, client = %addr, "Connection closed");
413+
} else {
414+
error!(error = %e, client = %addr, "Connection error");
415+
}
403416
}
404417
}
405418
Err(e) => {
@@ -414,7 +427,11 @@ fn spawn_gateway_connection(
414427
} else {
415428
tokio::spawn(async move {
416429
if let Err(e) = service.serve(stream).await {
417-
error!(error = %e, client = %addr, "Connection error");
430+
if is_benign_connection_close(e.as_ref()) {
431+
debug!(error = %e, client = %addr, "Connection closed");
432+
} else {
433+
error!(error = %e, client = %addr, "Connection error");
434+
}
418435
}
419436
});
420437
}

0 commit comments

Comments
 (0)