fix: Improve shutdown process for IRC Gateway and Server Directory services

This commit is contained in:
HueByte
2026-02-19 12:25:33 +01:00
parent 963c6d3384
commit 1bf32450fd
2 changed files with 13 additions and 10 deletions
+11 -4
View File
@@ -141,17 +141,24 @@ public sealed class IrcGatewayService : BackgroundService
public override async Task StopAsync(CancellationToken cancellationToken)
{
// Cancel ExecuteAsync first so listeners stop accepting
await base.StopAsync(cancellationToken);
// Force-close any remaining client connections
foreach (var (_, conn) in _connections)
{
try
{
await conn.SendAsync("ERROR :Server shutting down");
await conn.DisposeAsync();
await conn.SendAsync("ERROR :Server shutting down")
.WaitAsync(TimeSpan.FromSeconds(2));
}
catch { }
finally
{
try { await conn.DisposeAsync(); }
catch { }
}
}
_connections.Clear();
await base.StopAsync(cancellationToken);
}
}