Commit 20e5e86
fix(audience-session): emit session_end before flipping _initialized in Shutdown
The two-phase refactor broke Shutdown_FiresSessionEnd. Phase 1 flipped
_initialized to false, then Phase 2 called session.Dispose(). Session
fires session_end through ImmutableAudience.Track, which guards on
CanTrack() = _initialized && _consent.CanTrack(). With _initialized
already false, Track dropped the event on the floor.
Added Session.EmitEndAndSeal — an emit-only variant of End() that
fires session_end and resets state but does not drain the heartbeat
timer. Shutdown calls it under _initLock before the flag flip, so
Track's gate still lets session_end through. Heartbeat timer drain
continues to happen in Phase 2 via session.Dispose(); the second
End() inside Dispose no-ops because EmitEndAndSeal already cleared
_sessionId.
Lock hold time is unchanged: EmitEndAndSeal takes Session._lock for
microseconds to compute duration and reset state, then releases
before calling SafeTrack → Track → Enqueue (which takes EventQueue's
_drainLock, also microseconds). Nothing blocking runs under _initLock.
Also drops the column-aligned capture block in Shutdown Phase 1 —
dotnet-format rejects the extra whitespace, so one assignment per line.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 7f79159 commit 20e5e86
2 files changed
Lines changed: 45 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
196 | 221 | | |
197 | 222 | | |
198 | 223 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
547 | 547 | | |
548 | 548 | | |
549 | 549 | | |
550 | | - | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
551 | 558 | | |
552 | 559 | | |
553 | 560 | | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
560 | 573 | | |
561 | 574 | | |
562 | 575 | | |
| |||
0 commit comments