The gauge was maintained by conditional inc on "this sessionId isn't in the in-memory `docs` Map yet" and dec on "last client for the sessionId left." Because `docs` caches entries indefinitely — even after every client disconnects — a reconnect found the doc still cached, skipped the inc, then decremented again on the next disconnect. Every reconnect-after-last-disconnect leaked one decrement. After a day of normal reload / wifi-blip / tab-hibernate patterns the gauge hit -182. Replace the transitions with a `set()` derived from the live `conns` map: count distinct session ids with at least one open WebSocket. Self-correcting, no drift possible. Extract `countActiveSessions()` as a pure helper + unit tests including a regression case that simulates repeated reconnect/ disconnect cycles on one session and asserts the count never goes negative. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| app | ||
| public | ||
| Dockerfile | ||
| package.json | ||
| react-router.config.ts | ||
| server.ts | ||
| tsconfig.json | ||
| vite.config.ts | ||
| vitest.config.ts | ||