fix(tunnel): recover gateway reconnection after disconnect

- exit the gateway agent loop immediately when the control stream reaches EOF
This commit is contained in:
token
2026-03-22 16:01:51 +08:00
parent 0dbc89d543
commit bca6bf269c
2 changed files with 5 additions and 5 deletions
@@ -115,7 +115,8 @@ public sealed partial class AgentClientConnection : IAsyncDisposable
switch (text)
{
case null:
break;
Log.LogClosed(_logger, ClientId);
return;
case Ping:
Log.LogRecvPing(_logger, ClientId);
+3 -4
View File
@@ -30,22 +30,21 @@ public class Worker : BackgroundService
var serverClient = new ServerClient(monitorServer, tunnel,
_services.GetRequiredService<ILogger<ServerClient>>());
await monitorServer.RegisterNodeAsync(tunnel, stoppingToken);
while (!stoppingToken.IsCancellationRequested)
{
await MonitorServerAsync(serverClient, tunnel, stoppingToken);
await MonitorServerAsync(monitorServer, serverClient, tunnel, stoppingToken);
_logger.LogInformation("尝试重新连接到服务器...");
await Task.Delay(tunnel.ReconnectInterval, stoppingToken);
_logger.LogInformation("重新连接到服务器中...");
}
}
private async Task MonitorServerAsync(ServerClient serverClient,
private async Task MonitorServerAsync(MonitorServer monitorServer, ServerClient serverClient,
Tunnel tunnel, CancellationToken stoppingToken)
{
try
{
await monitorServer.RegisterNodeAsync(tunnel, stoppingToken);
await serverClient.TransportCoreAsync(tunnel, stoppingToken);
}
catch (UnauthorizedAccessException e)