From f2d21ad8136d02f7d67074117be1e233694ccc5d Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 9 Nov 2022 18:18:55 -0600 Subject: [PATCH] shut down on broken pipe --- azalea-protocol/src/connect.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs index c0c1a622..2400c712 100644 --- a/azalea-protocol/src/connect.rs +++ b/azalea-protocol/src/connect.rs @@ -11,6 +11,7 @@ use crate::write::write_packet; use azalea_auth::sessionserver::SessionServerError; use azalea_crypto::{Aes128CfbDec, Aes128CfbEnc}; use bytes::BytesMut; +use log::info; use std::fmt::Debug; use std::marker::PhantomData; use std::net::SocketAddr; @@ -131,13 +132,22 @@ where { /// Write a packet to the server. pub async fn write(&mut self, packet: W) -> std::io::Result<()> { - write_packet( + if let Err(e) = write_packet( &packet, &mut self.write_stream, self.compression_threshold, &mut self.enc_cipher, ) .await + { + // detect broken pipe + if e.kind() == std::io::ErrorKind::BrokenPipe { + info!("Broken pipe, shutting down connection.") + self.shutdown(); + } + return Err(e); + } + Ok(()) } /// End the connection.