From bca6bf269cb6fe4ddcd192ca5bdaeffc0dd09d77 Mon Sep 17 00:00:00 2001 From: token Date: Sun, 22 Mar 2026 16:01:51 +0800 Subject: [PATCH] fix(tunnel): recover gateway reconnection after disconnect - exit the gateway agent loop immediately when the control stream reaches EOF --- src/FastGateway/Tunnels/AgentClientConnection.cs | 3 ++- src/TunnelClient/Worker.cs | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/FastGateway/Tunnels/AgentClientConnection.cs b/src/FastGateway/Tunnels/AgentClientConnection.cs index 5d99df4..1b359dd 100644 --- a/src/FastGateway/Tunnels/AgentClientConnection.cs +++ b/src/FastGateway/Tunnels/AgentClientConnection.cs @@ -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); diff --git a/src/TunnelClient/Worker.cs b/src/TunnelClient/Worker.cs index bda43a4..44d4871 100644 --- a/src/TunnelClient/Worker.cs +++ b/src/TunnelClient/Worker.cs @@ -30,22 +30,21 @@ public class Worker : BackgroundService var serverClient = new ServerClient(monitorServer, tunnel, _services.GetRequiredService>()); - 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)