mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5863] [MERGED] fix(server): bound graceful shutdown so supervisors never SIGKILL it #6972
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#6972
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?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5863
Author: @kolacheee
Created: 9/5/2026
Status: ✅ Merged
Merged: 9/5/2026
Merged by: @kolacheee
Base:
staging← Head:fix/5838-shutdown-deadline📝 Commits (4)
27525f6fix(server): bound graceful shutdown so supervisors never SIGKILL it (#5838)97d8ed6fix(server): keep the force-exit watchdog referenced (CodeRabbit)f99278cMerge branch 'staging' into fix/5838-shutdown-deadline57fe8f7fix(server): drop the unused force-exit timer handle (CI TS6133)📊 Changes
9 files changed (+276 additions, -19 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
packages/client/src/lib/support-diagnostics.ts(+7 -1)📝
packages/server/src/index.ts(+5 -0)📝
packages/server/src/lib/session-postmortem.ts(+2 -2)➕
packages/server/src/lib/shutdown-deadline.ts(+79 -0)📝
packages/server/src/routes/updates.routes.ts(+5 -0)➕
scripts/regressions/shutdown-deadline.regression.ts(+154 -0)📝
scripts/regressions/termux-postmortem.regression.ts(+18 -15)📝
scripts/regressions/tsconfig.character-activity.json(+5 -1)📄 Description
Linked issue
Follow-up to #5838 (closed by #5839) — the shutdown half of that investigation. No separate issue was opened; the field evidence and decision live in this #5838 comment.
Why this change
A SteamOS reporter's logs caught our graceful shutdown taking 39 seconds:
holo-earlyoomsent SIGTERM at 16:24:35 and the process exited (cleanly, status 0) at 16:25:14. The cause is thatshutdown()awaitsapp.close()without any bound, and Fastify's close waits for open connections — a phone browser holding an SSE stream is enough. earlyoom treats the stop as failed after ~10 s; Docker's stop timeout is 10 s; systemd has its own. Past any of those windows, an orderly stop escalates to a SIGKILL that bypasses the onClose chain (closeDB → fileStore.close → flush(true)) and drops the store's debounced writes. The slow-close bug is ours and platform-independent; the SteamOS box just happened to photograph it.What changed
lib/shutdown-deadline.ts—armShutdownDeadline(app, context)arms two unref'd watchdogs: at 4 s it severs open connections (app.server.closeAllConnections()) so close can proceed to the flush — the gentle remedy for the exact hang observed; at 8 s, if close is still stuck (e.g. inside the flush itself), it logs and force-exits — whatever hasn't finished by then is precisely what the supervisor was about to SIGKILL anyway, except we leave on our own terms with the session-postmortem exit stamp written.index.tsand the update-restart inupdates.routes.ts(stamp → arm → close, so the "restart" postmortem stamp always lands before any possible exit).admin.routes.tsdeliberately not armed: it already severs connections on its own 30 s timer, and it spawns the relaunch child only after close — a blind stage-2 force-exit would leave the server down after a settings-restart click. The lane pins this reasoning so it isn't "unified" away later.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
"forced"session exit kind instead of"clean"(a cut-short close may have truncated the flush, and a pasted Support Diagnostics must say so rather than alibi it — the client renders it in plain words); the lane's children are pinned toLOG_LEVEL=warn/NODE_ENV=productionso a user's documented LOG_LEVEL knob can't fail the lane (the review demonstrated that failure live, and the fix is verified by running the lane underLOG_LEVEL=error); and the failure-path timers are sized to report their own assertion messages inside the lane runner's 30 s budget.shutdown-deadlinelane: three child-process functional tests (via the same tsx resolution the lane runner uses) observe the real helper — stage-2 force-exits with status 0 and the expected log line while a hung close holds the loop open; stage-1 fires before stage-2 and actually invokescloseAllConnections; unref'd watchdogs never pin an otherwise-finished process — plus source pins for the wiring order at both call sites and the admin exemption.termux-postmortemlane updated: its stamp-before-close pin now asserts the full stamp → arm → close order on the updates route.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)UI evidence (if applicable)
Not applicable — server shutdown behavior only.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.