A Game decided during shutdown is lost #434
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
spec
wayfinder:grilling
wayfinder:map
wayfinder:prototype
wayfinder:research
wayfinder:task
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
amaurycoudr/chess-project#434
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What happens
A Game decided while the API shuts down is dropped.
GamesService.recordstarts its write without awaiting it and tracks it ininFlight(apps/api/src/games/games.service.ts:180-185). On shutdown nothing waits forinFlight, whileDatabaseService.onApplicationShutdowncloses the pool (apps/api/src/common/database.service.ts:28-30). The write fails and is only logged.Every deploy restarts the API, so any Game that ends in that window is lost. Losing the live Room on restart is accepted (ADR 0015); losing a Game that was already decided is not.
Done when
GamesServicewaits onsettled()inbeforeApplicationShutdown, so pending writes finish before the pool closes.Investigated: does not reproduce on main. A test that decides a Game by resignation, then closes the app without awaiting
settled()(write confirmed in flight), finds the Game stored. pg-pool'send()waits for checked-out clients, andstore()checks its client out before anything is awaited, so the commit finishes before the pool closes. Nest's express adapter waits for in-flight requests, and no timer decides a Game.A narrower gap, from reading code only: if the pool is saturated (pg default max 10) when a Game is decided during shutdown,
store()'s connect is queued, and pg-pool neither serves nor rejects that queue onceendingis set, so the write would hang silently.beforeApplicationShutdown() { await this.settled(); }onGamesServicewould close it, but only a contrived test (a 1-client pool) can show it.Owner decision: close as not reproducible, or rescope to the pool-saturation case.