fix(sessions): drop per-session event metrics after the session dispose (WRK-008, #253)

This commit is contained in:
Joseph Doherty
2026-12-03 09:57:41 -05:00
parent 196465ef9c
commit 9c3a4c0eae
4 changed files with 44 additions and 4 deletions
+1 -1
View File
@@ -106,7 +106,7 @@ The scalar fields mirror the counters and gauges. The three dictionaries provide
- `CommandFailuresByMethod` keys by gRPC method name.
- `EventsByFamily` keys by event family (the `Family` enum on a worker event).
- `EventsBySession` keys by `sessionId`; entries are removed via `RemoveSessionEvents` when a session closes so the map does not grow without bound.
- `EventsBySession` keys by `sessionId`; entries are removed via `RemoveSessionEvents` when a session closes so the map does not grow without bound. The removal runs after the session (and with it the worker client, whose dispose waits for its read loop) is disposed: on the kill path the read loop is cancelled but not awaited, and a frame it had already read would otherwise re-create the entry after the removal.
`EventsReceived` is read with `Interlocked.Read(ref _eventsReceived)` because `EventReceived` increments it via `Interlocked.Increment` outside the lock to keep the event-ingestion path non-blocking. `CommandsStarted`, `CommandsSucceeded`, `CommandsFailed`, and `CommandFailuresByMethod` are read the same way: the command counters run two-to-three times per gRPC call, so they are recorded with `Interlocked` and a `ConcurrentDictionary` rather than under `_syncRoot` (PERF-02). The two queue depths are pulled from their registered sources before the lock is taken, since those delegates reach into subscriber channels and worker clients.
+1 -1
View File
@@ -196,7 +196,7 @@ catch (Exception exception)
}
```
`RollBackOpenAsync` faults the session and, when it had been registered, routes it through `RemoveSessionAsync` — the single removal path every teardown uses, which deregisters, drops the session's per-session event metrics, releases the slot and disposes, in that order. The order matters because releasing the semaphore before disposal would let the next open race the worker process tear-down on the same machine. A session that was never registered (id collision) releases the slot and disposes directly. The open-session gauge is not touched by the rollback: `SessionOpened` is recorded inside the attach gate described next, after which nothing in the open sequence can fail.
`RollBackOpenAsync` faults the session and, when it had been registered, routes it through `RemoveSessionAsync` — the single removal path every teardown uses, which deregisters, releases the slot, disposes, and then drops the session's per-session event metrics (after the dispose, so a worker read loop still finishing a frame cannot re-create the entry). The order matters because releasing the semaphore before disposal would let the next open race the worker process tear-down on the same machine. A session that was never registered (id collision) releases the slot and disposes directly. The open-session gauge is not touched by the rollback: `SessionOpened` is recorded inside the attach gate described next, after which nothing in the open sequence can fail.
#### Close or kill during worker startup