From 8f674316234400ae5fbba2dccc4227b4317d55f2 Mon Sep 17 00:00:00 2001 From: wenzuhuai Date: Wed, 28 Jan 2026 13:38:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20handleDisconnect=20?= =?UTF-8?q?=E5=9C=A8=20disconnect=20=E5=A4=B1=E8=B4=A5=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=20.disconnected=20=E4=BA=8B=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Nats/NatsConnection.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/Nats/NatsConnection.swift b/Sources/Nats/NatsConnection.swift index 5fbac7d..5ad73f9 100644 --- a/Sources/Nats/NatsConnection.swift +++ b/Sources/Nats/NatsConnection.swift @@ -989,11 +989,13 @@ class ConnectionHandler: ChannelInboundHandler { promise.futureResult.whenComplete { result in do { try result.get() - self.fire(.disconnected) } catch { // 降级为 debug:网络断开时 TLS 无法完成正常关闭握手是预期行为 logger.debug("Connection closed with error (will reconnect): \(error)") } + // 无论成功还是失败,都要触发 .disconnected 事件 + // 这样上层才能感知到连接已断开 + self.fire(.disconnected) // Only start reconnect after disconnect is complete self.handleReconnect() }