From ec4618db8720ea40ba9bfd4bbbacec8cf03b8de8 Mon Sep 17 00:00:00 2001 From: wenzuhuai Date: Fri, 23 Jan 2026 09:58:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E8=BF=9E=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E5=90=8E=E9=87=8D=E7=BD=AE=20outstandingPings=20=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E5=99=A8=EF=BC=8C=E4=BF=AE=E5=A4=8D=E9=A2=91=E7=B9=81?= =?UTF-8?q?=E9=87=8D=E8=BF=9E=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, 4 insertions(+) diff --git a/Sources/Nats/NatsConnection.swift b/Sources/Nats/NatsConnection.swift index 07c0f77..5fbac7d 100644 --- a/Sources/Nats/NatsConnection.swift +++ b/Sources/Nats/NatsConnection.swift @@ -356,6 +356,10 @@ class ConnectionHandler: ChannelInboundHandler { guard let channel = self.channel else { throw NatsError.ClientError.internalError("empty channel") } + + // 重连成功后重置 ping 计数器,避免累积的失败计数导致立即断开 + self.outstandingPings.store(0, ordering: .relaxed) + // Schedule the task to send a PING periodically let pingInterval = TimeAmount.nanoseconds(Int64(self.pingInterval * 1_000_000_000)) self.pingTask = channel.eventLoop.scheduleRepeatedTask(