Fix chat channel disconnect crash
Investigate the reported BaseChannel.Disconnect NullReferenceException from player-status and TCP disconnect callbacks in a dedicated worktree. Trace session/channel lifetime and concurrency, reproduce the failure with regression tests, and fix the underlying cause without hiding lifecycle errors. Acceptance: disconnect safely handles the reproduced lifecycle and concurrent channel activity; targeted tests and ChatEngine build pass. Findings: ConnectedClients returned a fresh List on every access, so lock(ConnectedClients) never synchronized membership operations. Both disconnect overloads and snapshots could race; notifications inside RemoveAll also allowed reentrant removal. Control run: 4/6 initial regressions failed (concurrent collection exceptions, unrelated member loss on reentry, live snapshots, stale socket removing replacement). Fix: private membership list with a stable lock, synchronized snapshots/add/removal, sends/logging outside mutation, session-reference removal for socket disconnects. Validation: ChatEngine build passed; 280 selected chat/auth/channel tests passed on the existing .NET 8 SDK container, and all 9 new membership tests passed in 10 repeated runs. Host .NET lacks the .NET 8/ASP.NET runtimes, so test execution used the container. Exact production NullReferenceException interleaving was not reproduced; related list corruption and concurrent collection failures were reproduced. Earlier authentication EndOfStreamException remains separate and uninvestigated. Worktree: /home/mathias/Projects/worktrees/engines-chat-disconnect; branch fix/chat-channel-disconnect-crash. Committed as 8fb63017b. Pull request #2945: https://git.project-rk.com/prk/engines/pulls/2945 (fix/chat-channel-disconnect-crash → develop).
Checklist
2 of 2 complete- Trace disconnect/channel lifetime and reproduce the failure with regression tests.
- Fix channel membership synchronization and verify targeted tests and ChatEngine build.
- Area
- Project Rubi-Ka
- Project
- engines
- Kind
- Bug
- Task ID
tsk_s9hvtzqk7m- Updated