Fix engine connection lifecycle: leaks, crashes, unhandled rejections - #109
Merged
Conversation
Hardens the WebSocket/networking and lifecycle layer of the engine, which previously had no test coverage and several process-crash paths. ConnectionTracker: remove connections by identity instead of a stored index. The index map went stale the moment connections.sort() ran on every add, so a disconnect removed the wrong socket (leaking the dead one, which kept receiving broadcasts). Add ConnectionTracker.test.ts covering multi-connection removal, role ordering, and interleaved churn. Socket handlers: register an "error" listener on every socket so an abnormal reset logs instead of throwing an unhandled EventEmitter error that crashes the process. Guard Send with a readyState check + try/catch so one dead socket can't abort a broadcast to everyone else. Close rejected connections (GameWebSocket catch + attachSocketHandler now throws on unknown roles) instead of leaking open sockets. Lifecycle: install process-level unhandledRejection/uncaughtException handlers so a stray async failure (webhook, telemetry, admin state eval) no longer tears down a live match, and attach .catch to the previously un-awaited async calls. Also add the missing return after the game-complete branch that broadcast an extra Tick after EndGameState. Verified: tsc --noEmit clean; jest 15 suites / 46 tests passing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hardens the WebSocket/networking and lifecycle layer of the engine, which previously had no test coverage and several process-crash paths.
ConnectionTracker: remove connections by identity instead of a stored index. The index map went stale the moment connections.sort() ran on every add, so a disconnect removed the wrong socket (leaking the dead one, which kept receiving broadcasts). Add ConnectionTracker.test.ts covering multi-connection removal, role ordering, and interleaved churn.
Socket handlers: register an "error" listener on every socket so an abnormal reset logs instead of throwing an unhandled EventEmitter error that crashes the process. Guard Send with a readyState check + try/catch so one dead socket can't abort a broadcast to everyone else. Close rejected connections (GameWebSocket catch + attachSocketHandler now throws on unknown roles) instead of leaking open sockets.
Lifecycle: install process-level unhandledRejection/uncaughtException handlers so a stray async failure (webhook, telemetry, admin state eval) no longer tears down a live match, and attach .catch to the previously un-awaited async calls. Also add the missing return after the game-complete branch that broadcast an extra Tick after EndGameState.
Verified: tsc --noEmit clean; jest 15 suites / 46 tests passing.