Commit 4a03d88
refactor(audience-session): hoist Identity out of _initLock; double-seal in Shutdown
Two Cursor Bugbot findings on 63b13bb:
SetConsent held _initLock across Identity.GetOrCreate / Identity.Get.
On the None → Anonymous/Full upgrade path, GetOrCreate creates
directories and writes a UUID file — real disk I/O under the lock.
Moved the capture outside _initLock. Identity's own _sync lock
serialises the I/O; TOCTOU on previous is accepted — a racing
SetConsent fires its own PUT and our slightly-stale anonymousId
still identifies the user.
Shutdown's outside-lock EmitEndAndSeal targeted whatever _session
pointed to at call time. A Reset completing fully (including new
session Start()) in the narrow window before Shutdown's lock acquire
would leave the new session's session_start on the wire with no
matching session_end — Shutdown disposes the new session after
flipping _initialized=false, so Track drops the closing event.
Added a second EmitEndAndSeal inside the lock as a race guard.
Idempotent on the same instance (no-op via _sessionId null check);
the slow path only runs when the race actually happened.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 63b13bb commit 4a03d88
1 file changed
Lines changed: 27 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
374 | 374 | | |
375 | 375 | | |
376 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
377 | 395 | | |
378 | 396 | | |
379 | 397 | | |
380 | 398 | | |
381 | 399 | | |
382 | | - | |
383 | 400 | | |
384 | 401 | | |
385 | 402 | | |
386 | | - | |
387 | 403 | | |
388 | 404 | | |
389 | 405 | | |
| |||
397 | 413 | | |
398 | 414 | | |
399 | 415 | | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | 416 | | |
407 | 417 | | |
408 | 418 | | |
| |||
555 | 565 | | |
556 | 566 | | |
557 | 567 | | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
558 | 577 | | |
559 | 578 | | |
560 | 579 | | |
| |||
0 commit comments