From 5da19c39bb56f7a979b213f4824c928ae1552461 Mon Sep 17 00:00:00 2001 From: sistemd Date: Thu, 28 Mar 2024 18:08:46 +0100 Subject: [PATCH] make sure pings, pongs, and close messages are handled correctly --- crates/rpc/src/jsonrpc/websocket/logic.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/rpc/src/jsonrpc/websocket/logic.rs b/crates/rpc/src/jsonrpc/websocket/logic.rs index c6b67e9c4b..a5ea8bbd87 100644 --- a/crates/rpc/src/jsonrpc/websocket/logic.rs +++ b/crates/rpc/src/jsonrpc/websocket/logic.rs @@ -129,16 +129,16 @@ async fn read( let request = match receiver.next().await { Some(Ok(Message::Text(x))) => x.into_bytes(), Some(Ok(Message::Binary(x))) => x, - Some(Ok(Message::Ping(_))) - | Some(Ok(Message::Pong(_))) - | Some(Ok(Message::Close(_))) => continue, - // Both of these are client disconnects according to the axum example - // https://docs.rs/axum/0.6.20/axum/extract/ws/index.html#example + Some(Ok(Message::Ping(_))) | Some(Ok(Message::Pong(_))) => { + // Ping and pong messages are handled automatically by axum. + continue; + } + // All of the following indicate client disconnection. Some(Err(e)) => { tracing::trace!(error=%e, "Client disconnected"); break; } - None => { + Some(Ok(Message::Close(_))) | None => { tracing::trace!("Client disconnected"); break; }