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(