[GH-ISSUE #5512] Automatic-backup failure path can hard-exit the server via unhandledRejection #3063

Closed
opened 2026-10-21 05:59:18 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Aug 25, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5512

Originally assigned to: @kolacheee on GitHub.

Found while auditing #5506 for paths that could silently kill the Termux server.

runAutomaticBackupIfDue is invoked from an hourly timer as void runAutomaticBackupIfDue(). Its catch block itself awaits loadAutomaticBackupSettings / saveAutomaticBackupSettings (packages/server/src/routes/backup.routes.ts:3325-3328 on staging). If a backup fails and the settings write in the catch also throws (disk full is the realistic case — the same condition that fails backups), the rejection escapes the void timer call and reaches the process-fatal unhandledRejection handler (packages/server/src/index.ts:70-75), which calls process.exit(1).

Consequences: the whole server hard-exits from a background timer, and on Termux start-termux.sh has no restart loop, so the instance stays down. This is the only timer-driven path found in the audit where a rejection can escape to the fatal handler — every other scheduler/watchdog routes into a catch.

Fix shape: wrap the settings-save inside the catch in its own try/catch (log and continue). Only affects installs with automatic backup enabled (off by default).

Originally created by @kolacheee on GitHub (Aug 25, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5512 Originally assigned to: @kolacheee on GitHub. Found while auditing #5506 for paths that could silently kill the Termux server. `runAutomaticBackupIfDue` is invoked from an hourly timer as `void runAutomaticBackupIfDue()`. Its catch block itself awaits `loadAutomaticBackupSettings` / `saveAutomaticBackupSettings` (`packages/server/src/routes/backup.routes.ts:3325-3328` on staging). If a backup fails **and** the settings write in the catch also throws (disk full is the realistic case — the same condition that fails backups), the rejection escapes the `void` timer call and reaches the process-fatal `unhandledRejection` handler (`packages/server/src/index.ts:70-75`), which calls `process.exit(1)`. Consequences: the whole server hard-exits from a background timer, and on Termux `start-termux.sh` has no restart loop, so the instance stays down. This is the only timer-driven path found in the audit where a rejection can escape to the fatal handler — every other scheduler/watchdog routes into a catch. Fix shape: wrap the settings-save inside the catch in its own try/catch (log and continue). Only affects installs with automatic backup enabled (off by default).
bsakaguchi 2026-10-21 05:59:18 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Aug 25, 2026):

@kolacheee I am taking the minimal implementation into one release-hardening PR against staging now, using the fix boundaries from your audit. I will keep your diagnosis credited in the PR and avoid expanding scope beyond the four verified paths.

<!-- gh-comment-id:5409719963 --> @SpicyMarinara commented on GitHub (Aug 25, 2026): @kolacheee I am taking the minimal implementation into one release-hardening PR against staging now, using the fix boundaries from your audit. I will keep your diagnosis credited in the PR and avoid expanding scope beyond the four verified paths.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#3063
No description provided.