From a93f71c702bad2aa23c99d32a7d50c2d2f373fc7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E3=82=88=E3=81=A3=E3=82=AD=E3=83=B3=E3=82=B0?= <4476tv@gmail.com> Date: Sun, 28 Jun 2026 00:35:25 +0900 Subject: [PATCH] Fixed listener loop dying on ChannelClosedException (#4) * fix: Fixed an issue where all communications could not be processed due to ChannelClosedException. * fix: Change WriteAsync to TryWrite to make it safer. --- Hazel/Udp/UdpConnectionListener.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Hazel/Udp/UdpConnectionListener.cs b/Hazel/Udp/UdpConnectionListener.cs index 23c7a6a..2994b89 100644 --- a/Hazel/Udp/UdpConnectionListener.cs +++ b/Hazel/Udp/UdpConnectionListener.cs @@ -3,6 +3,7 @@ using System.Collections.Concurrent; using System.Net; using System.Net.Sockets; using System.Threading; +using System.Threading.Channels; using System.Threading.Tasks; using Microsoft.Extensions.ObjectPool; using Serilog; @@ -138,6 +139,7 @@ namespace Impostor.Hazel.Udp Logger.Fatal("Hazel read 0 bytes from UDP server socket."); continue; } + await ProcessData(data); } catch (SocketException) { @@ -149,8 +151,11 @@ namespace Impostor.Hazel.Udp // Socket was disposed, don't care. return; } - - await ProcessData(data); + catch (ChannelClosedException) + { + // Client closed, pretend it didn't happen + continue; + } } } catch (Exception e) @@ -191,7 +196,7 @@ namespace Impostor.Hazel.Udp } // Write to client. - await client.Pipeline.Writer.WriteAsync(data.Buffer); + client.Pipeline.Writer.TryWrite(data.Buffer); } /// -- 2.39.5