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.