fix: prevent SQLite corruption by checkpointing WAL and closing DB on shutdown
The database was never properly closed on SIGINT/SIGTERM — WAL files were left in a partially-written state causing "database disk image is malformed" errors. Adds WAL checkpoint on close, synchronous=NORMAL pragma, SIGTERM handlers, and a store.close() method that flushes all pending writes before exit. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -650,18 +650,31 @@ export async function runDashboard(port: number, opts: { paused?: boolean; dev?:
|
||||
cronRunner.stop();
|
||||
notifier.stop();
|
||||
if (mergeRetryTimer) clearTimeout(mergeRetryTimer);
|
||||
store.stopWatching();
|
||||
store.close();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on("SIGTERM", () => {
|
||||
stuckTaskDetector.stop();
|
||||
triage.stop();
|
||||
scheduler.stop();
|
||||
cronRunner.stop();
|
||||
notifier.stop();
|
||||
if (mergeRetryTimer) clearTimeout(mergeRetryTimer);
|
||||
store.close();
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
|
||||
// Dev mode: simplified SIGINT handler (no engine components)
|
||||
// Dev mode: simplified shutdown handlers (no engine components)
|
||||
if (opts.dev) {
|
||||
process.on("SIGINT", () => {
|
||||
const devShutdown = () => {
|
||||
notifier.stop();
|
||||
store.stopWatching();
|
||||
store.close();
|
||||
process.exit(0);
|
||||
});
|
||||
};
|
||||
process.on("SIGINT", devShutdown);
|
||||
process.on("SIGTERM", devShutdown);
|
||||
}
|
||||
|
||||
const server = app.listen(selectedPort);
|
||||
|
||||
Reference in New Issue
Block a user