From 025cab9c5b0b852a10aef35c3b3ab558de8b5148 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 29 Nov 2024 16:03:29 +0100 Subject: [PATCH 1/3] fix: ignore IO error after close has been sent This PR fixes that after the close reason has been soketto is trying to close down the I/O stream but it's possible that it's already closed down by the other end after it receives the close message. So, after this change the actual websocket close message is prioritized and the actual I/O close status is ignored because once the websocket close reason is sent to the other side then it's regarded as clean shutdown. --- src/connection.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/connection.rs b/src/connection.rs index db624ee4..44dab83b 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -385,7 +385,6 @@ impl Receiver { OpCode::Pong => Ok(None), OpCode::Close => { log::trace!("{}: Acknowledging CLOSE to sender", self.id); - self.is_closed = true; let (mut header, reason) = close_answer(&self.ctrl_buffer)?; // Write back a Close frame let mut unused = Vec::new(); @@ -416,7 +415,10 @@ impl Receiver { .await; } self.flush().await?; - self.writer.lock().await.close().await?; + // Close down the connection but the IO stream could already be closed and + // we don't want propagate such error to the user if the IO was already closed. + _ = self.writer.lock().await.close().await; + self.is_closed = true; Ok(reason) } OpCode::Binary From e20f93a88d8113df6742fb1228434a1090fb1693 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 29 Nov 2024 17:22:12 +0100 Subject: [PATCH 2/3] Update src/connection.rs --- src/connection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection.rs b/src/connection.rs index 44dab83b..92bb0ae3 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -415,7 +415,7 @@ impl Receiver { .await; } self.flush().await?; - // Close down the connection but the IO stream could already be closed and + // Close down the connection but the I/O stream could already be closed and // we don't want propagate such error to the user if the IO was already closed. _ = self.writer.lock().await.close().await; self.is_closed = true; From 5afd9ed7b67121d9f9a25d9464f44308c7d3f9db Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 29 Nov 2024 17:22:26 +0100 Subject: [PATCH 3/3] Update src/connection.rs --- src/connection.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/connection.rs b/src/connection.rs index 92bb0ae3..9ae2d4f3 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -416,7 +416,7 @@ impl Receiver { } self.flush().await?; // Close down the connection but the I/O stream could already be closed and - // we don't want propagate such error to the user if the IO was already closed. + // we don't want propagate such error to the user if the I/O was already closed. _ = self.writer.lock().await.close().await; self.is_closed = true; Ok(reason)