From 43d7c428e317f503dda899cade9e3ec8024de4de Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 18 Apr 2025 00:32:31 +0200 Subject: fix another panic on disconnect and slightly optimize client events loop --- azalea-client/src/plugins/connection.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'azalea-client/src') diff --git a/azalea-client/src/plugins/connection.rs b/azalea-client/src/plugins/connection.rs index b462535e..30ac5d20 100644 --- a/azalea-client/src/plugins/connection.rs +++ b/azalea-client/src/plugins/connection.rs @@ -126,7 +126,11 @@ fn poll_all_writer_tasks(mut conn_query: Query<&mut RawConnection>) { // this needs to be done at some point every update to make sure packets are // actually sent to the network - net_conn.poll_writer(); + if net_conn.poll_writer().is_some() { + // means the writer task ended + conn.network = None; + conn.is_alive = false; + } } } } @@ -319,9 +323,11 @@ impl NetworkConnection { Ok(()) } - pub fn poll_writer(&mut self) { + /// Makes sure packets get sent and returns Some(()) if the connection has + /// closed. + pub fn poll_writer(&mut self) -> Option<()> { let poll_once_res = future::poll_once(&mut self.writer_task); - future::block_on(poll_once_res); + future::block_on(poll_once_res) } pub fn set_compression_threshold(&mut self, threshold: Option) { @@ -348,6 +354,7 @@ async fn write_task( break; }; } + trace!("write task is done"); } -- cgit v1.2.3