From 0764b8646f82b7aa1c0e2754815316efa81ce17a Mon Sep 17 00:00:00 2001 From: gamer147 Date: Mon, 1 Jun 2026 11:11:31 -0400 Subject: [PATCH] feat(battle-node): capture session-scoped CT in BattleSession.RunAsync --- SVSim.BattleNode/Sessions/BattleSession.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/SVSim.BattleNode/Sessions/BattleSession.cs b/SVSim.BattleNode/Sessions/BattleSession.cs index fbab589..8ab6b03 100644 --- a/SVSim.BattleNode/Sessions/BattleSession.cs +++ b/SVSim.BattleNode/Sessions/BattleSession.cs @@ -18,6 +18,19 @@ public sealed class BattleSession private readonly WebSocket _ws; private readonly ILogger _log; + /// + /// Cancellation token for the session lifetime, captured from 's + /// parameter. Read by all send helpers so host shutdown promptly terminates pending + /// writes (was CancellationToken.None on every send pre-this-slice). + /// + /// + /// Defaults to when hasn't + /// run — e.g. unit tests that drive directly without + /// going through the WS pump. None of those tests exercise send code, so the default + /// is safe. + /// + private CancellationToken _sessionCt; + public string BattleId { get; } public long ViewerId { get; } public BattleSessionPhase Phase { get; internal set; } = BattleSessionPhase.AwaitingInitNetwork; @@ -37,6 +50,7 @@ public sealed class BattleSession /// public async Task RunAsync(CancellationToken cancellation) { + _sessionCt = cancellation; await SendEioOpenAsync(cancellation); var buffer = new byte[8192];