mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
fix: Improve shutdown process for IRC Gateway and Server Directory services
This commit is contained in:
@@ -141,17 +141,24 @@ public sealed class IrcGatewayService : BackgroundService
|
|||||||
|
|
||||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
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)
|
foreach (var (_, conn) in _connections)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await conn.SendAsync("ERROR :Server shutting down");
|
await conn.SendAsync("ERROR :Server shutting down")
|
||||||
await conn.DisposeAsync();
|
.WaitAsync(TimeSpan.FromSeconds(2));
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
try { await conn.DisposeAsync(); }
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_connections.Clear();
|
_connections.Clear();
|
||||||
|
|
||||||
await base.StopAsync(cancellationToken);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,13 +177,9 @@ public sealed class ServerDirectoryService(
|
|||||||
|
|
||||||
public override async Task StopAsync(CancellationToken cancellationToken)
|
public override async Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (_connection is not null)
|
// Cancel ExecuteAsync first — it disposes the connection via await using
|
||||||
{
|
|
||||||
await _connection.DisposeAsync();
|
|
||||||
_connection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
await base.StopAsync(cancellationToken);
|
await base.StopAsync(cancellationToken);
|
||||||
|
_connection = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user