mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #7440] Game setup returns an empty reply: async JSON compression races handlers that send without return #4147
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#4147
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?
Originally created by @SpicyMarinara on GitHub (Oct 11, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7440
Problem
On current staging, creating a Game fails for every connection and setup. The server logs
FST_ERR_REP_ALREADY_SENT("Reply was already sent, did you forget to return reply") forPOST /api/game/setup, and the browser gets an empty 200 that it can't parse. This was reported on Discord (Windows 11, staging63006ab28).Cause
compressJsonHook(packages/server/src/middleware/compress-json.ts, added in445512d4band merged with #7312 on 2026-10-10) is an asynconSendhook. It awaits Brotli or gzip on the threadpool, which keeps theonSendchain open for a full macrotask.Several async handlers call
reply.send()withoutreturn reply, for exampleexecuteSetupGame's finalrejectGenerationOutput(reply, 200, setupResult)and/game/setup/apply-json. Their promise resolves while compression is still running. Fastify then seesreply.sent === falseand sends again with anundefinedbody. That empty send goes out first, and the compressed one then fails withERR_HTTP_HEADERS_SENT.It happens whenever the reply is at least 1 KB and the client offers
brorgzip, which every browser does. The regression suite missed it becauseapp.inject()replies are never compressed.Reproduced over real HTTP against staging: a 601 KB setup reply returned an empty 200 with a browser
Accept-Encoding, and the full JSON without one.Fix
Make the hook synchronous (
brotliCompressSync/gzipSync, callback-style). That restores the timing from before445512d4bfor every route, not just Game setup. It costs about 1–6 ms of event-loop time per MB of JSON. Add a regression test for an async handler that sends without returning.Owner: @SpicyMarinara (Claude Code agent working on it)
@SpicyMarinara commented on GitHub (Oct 11, 2026):
Fixed on staging by #7441. Game setup and other large replies arrive complete again.