]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Fixed listener loop dying on ChannelClosedException (#4)
authorよっキング <4476tv@gmail.com>
Sat, 27 Jun 2026 15:35:25 +0000 (00:35 +0900)
committerGitHub <noreply@github.com>
Sat, 27 Jun 2026 15:35:25 +0000 (17:35 +0200)
* 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

index 23c7a6ab645f244a4060ee614ae4714f7be6de1e..2994b89ac1649f7f0007a7f73746fc73d263422f 100644 (file)
@@ -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);
         }
 
         /// <summary>