77c99cc2302771855681556cd8a4fb3379346e9d
In PvP a BattleSession subscribes to both participants' FrameEmitted, and each RealParticipant raises it from its own WebSocket read loop -- two threads. The dispatch path (ComputeFrames + the relay PushAsync calls) mutates shared, non-thread-safe state: the BattleSessionState dictionaries (deck maps, post-swap hands, idx->cardId reveal map). Concurrent frames from both players could corrupt those dictionaries (InvalidOperationException / torn playSeq / wrong card identity). Add a per-session SemaphoreSlim _dispatchGate around the whole HandleFrameAsync so both read loops funnel through one critical section. ComputeFrames stays lock-free (the direct-call test seam is single-threaded). Analysis during the fix showed each OutboundSequencer is single-writer-per-instance in steady state (A's loop only writes B's Outbound and vice-versa), so the live race is the shared BattleSessionState, which the gate fully serializes. TDD: BattleSessionDispatchConcurrencyTests drives both participants to AfterReady, then fires TurnStart from both at once; the target PushAsync records peak in-flight dispatches. Red (MaxConcurrent=2) before the gate, green (1) after. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Description
The SV Simulator server code, including the DCG Engine, SVSim content, and an entrypoint for the official game client.
Languages
C#
100%