From 9a4f8bb3bfb410d46c9f0ad48a2c44e549787036 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 31 May 2024 14:44:26 +0200 Subject: [PATCH 1/4] server: logs when connection closed ws ping/pong --- server/src/transport/ws.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/server/src/transport/ws.rs b/server/src/transport/ws.rs index decfc34ca4..a5730889dd 100644 --- a/server/src/transport/ws.rs +++ b/server/src/transport/ws.rs @@ -84,6 +84,7 @@ where let stopped = conn.stop_handle.clone().shutdown(); let rpc_service = Arc::new(rpc_service); + let mut missed_pings = 0; tokio::pin!(stopped); @@ -103,7 +104,7 @@ where tokio::pin!(ws_stream); let result = loop { - let data = match try_recv(&mut ws_stream, stopped, ping_config).await { + let data = match try_recv(&mut ws_stream, stopped, ping_config, &mut missed_pings).await { Receive::ConnectionClosed => break Ok(Shutdown::ConnectionClosed), Receive::Stopped => break Ok(Shutdown::Stopped), Receive::Ok(data, stop) => { @@ -264,7 +265,12 @@ enum Receive { } /// Attempts to read data from WebSocket fails if the server was stopped. -async fn try_recv(ws_stream: &mut T, mut stopped: S, ping_config: Option) -> Receive +async fn try_recv( + ws_stream: &mut T, + mut stopped: S, + ping_config: Option, + missed_pings: &mut usize, +) -> Receive where S: Future + Unpin, T: StreamExt> + Unpin, @@ -274,7 +280,6 @@ where Some(p) => IntervalStream::new(interval_at(tokio::time::Instant::now() + p.ping_interval, p.ping_interval)), None => IntervalStream::pending(), }; - let mut missed = 0; tokio::pin!(inactivity_check); @@ -298,9 +303,10 @@ where Either::Left((Either::Right((_instant, rcv)), s)) => { if let Some(p) = ping_config { if last_active.elapsed() > p.inactive_limit { - missed += 1; + *missed_pings += 1; - if missed >= p.max_failures { + if *missed_pings >= p.max_failures { + tracing::debug!(target: LOG_TARGET, "WS ping/pong inactivity limit reached"); break Receive::ConnectionClosed; } } From 95e652bdba935d0d3170966a724b7e1d243ea53c Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 31 May 2024 14:47:39 +0200 Subject: [PATCH 2/4] Update server/src/transport/ws.rs --- server/src/transport/ws.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/transport/ws.rs b/server/src/transport/ws.rs index a5730889dd..46e10f7107 100644 --- a/server/src/transport/ws.rs +++ b/server/src/transport/ws.rs @@ -306,7 +306,7 @@ where *missed_pings += 1; if *missed_pings >= p.max_failures { - tracing::debug!(target: LOG_TARGET, "WS ping/pong inactivity limit reached"); + tracing::debug!(target: LOG_TARGET, "WS ping/pong inactivity limit reached; closing connection); break Receive::ConnectionClosed; } } From a312dcee03b69e4dd25d813ef5c0cd3ac29e55d1 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 31 May 2024 14:50:46 +0200 Subject: [PATCH 3/4] fix fmt --- server/src/transport/ws.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/src/transport/ws.rs b/server/src/transport/ws.rs index 46e10f7107..faa64e47a4 100644 --- a/server/src/transport/ws.rs +++ b/server/src/transport/ws.rs @@ -306,7 +306,11 @@ where *missed_pings += 1; if *missed_pings >= p.max_failures { - tracing::debug!(target: LOG_TARGET, "WS ping/pong inactivity limit reached; closing connection); + tracing::debug!( + target: LOG_TARGET, + "WS ping/pong inactivity limit `{}` exceeded; closing connection" + p.max_failures, + ); break Receive::ConnectionClosed; } } From 9f134a957a8710c5d54c238ad0e438b0223e6b41 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 31 May 2024 15:04:08 +0200 Subject: [PATCH 4/4] fix fmt2 --- server/src/transport/ws.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/transport/ws.rs b/server/src/transport/ws.rs index faa64e47a4..bcf3ee192a 100644 --- a/server/src/transport/ws.rs +++ b/server/src/transport/ws.rs @@ -308,7 +308,7 @@ where if *missed_pings >= p.max_failures { tracing::debug!( target: LOG_TARGET, - "WS ping/pong inactivity limit `{}` exceeded; closing connection" + "WS ping/pong inactivity limit `{}` exceeded; closing connection", p.max_failures, ); break Receive::ConnectionClosed;