mxgateway.sessions.open gauge never decremented for sessions closed by the timed sweep #168

Closed
opened 2026-10-22 06:05:32 -04:00 by dohertj2 · 1 comment
Owner

TryBeginCloseIfExpired sets _closeStarted, so CloseSessionCoreAsync skips SessionClosed() and the open-sessions gauge drifts upward even after reaping. Found during the OtOpcUa 2026-10-21 review cross-check (lmxopcua#735). Fix: decrement on every close path, including sweep closes.

`TryBeginCloseIfExpired` sets `_closeStarted`, so `CloseSessionCoreAsync` skips `SessionClosed()` and the open-sessions gauge drifts upward even after reaping. Found during the OtOpcUa 2026-10-21 review cross-check (lmxopcua#735). Fix: decrement on every close path, including sweep closes.
Author
Owner

Fixed on origin/main and verified (closing as part of #169).

  • 09666cc ("account SessionClosed for sweep-driven closes", merged in 7f0720f). SessionManager.CloseSessionCoreAsync now calls _metrics.SessionClosed() whenever !wasClosed && !result.AlreadyClosed && session.OpenRecorded. That includes the sweep path, where TryBeginCloseIfExpired has already set _closeStarted, and the SessionCloseStartedException path.
  • Test: SessionManagerTests.CloseExpiredLeasesAsync_SweptClose_AccountsSessionClosedExactlyOnce (theory over the sweep kinds) is green on macOS, and the full gateway suite is 1349/1349 on windev at 777fef9.
Fixed on origin/main and verified (closing as part of #169). - 09666cc ("account SessionClosed for sweep-driven closes", merged in 7f0720f). `SessionManager.CloseSessionCoreAsync` now calls `_metrics.SessionClosed()` whenever `!wasClosed && !result.AlreadyClosed && session.OpenRecorded`. That includes the sweep path, where `TryBeginCloseIfExpired` has already set `_closeStarted`, and the `SessionCloseStartedException` path. - Test: `SessionManagerTests.CloseExpiredLeasesAsync_SweptClose_AccountsSessionClosedExactlyOnce` (theory over the sweep kinds) is green on macOS, and the full gateway suite is 1349/1349 on windev at 777fef9.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/mxaccessgw#168