fix: move stale connection stat increments to detection site in RunPingTimerAsync

This commit is contained in:
Joseph Doherty
2026-02-23 00:41:12 -05:00
parent cd4ae3cce6
commit b7c0e321d9

View File

@@ -642,6 +642,8 @@ public sealed class NatsClient : IDisposable
if (Volatile.Read(ref _pingsOut) + 1 > _options.MaxPingsOut)
{
_logger.LogDebug("Client {ClientId} stale connection -- closing", Id);
Interlocked.Increment(ref _serverStats.StaleConnections);
Interlocked.Increment(ref _serverStats.StaleConnectionClients);
await SendErrAndCloseAsync(NatsProtocol.ErrStaleConnection, ClientClosedReason.StaleConnection);
return;
}
@@ -682,12 +684,6 @@ public sealed class NatsClient : IDisposable
break;
}
if (reason == ClientClosedReason.StaleConnection)
{
Interlocked.Increment(ref _serverStats.StaleConnections);
Interlocked.Increment(ref _serverStats.StaleConnectionClients);
}
_logger.LogDebug("Client {ClientId} connection closed: {CloseReason}", Id, reason);
}