Skip to content

fix: ensure SQLite WAL is checkpointed on graceful shutdown#1696

Merged
IceyLiu merged 1 commit intomainfrom
zynx/fix/db-graceful-shutdown
Mar 25, 2026
Merged

fix: ensure SQLite WAL is checkpointed on graceful shutdown#1696
IceyLiu merged 1 commit intomainfrom
zynx/fix/db-graceful-shutdown

Conversation

@piorpua
Copy link
Copy Markdown
Contributor

@piorpua piorpua commented Mar 25, 2026

Summary

  • Remove stale WAL (-wal) and shared-memory (-shm) sidecar files during DB recovery to prevent an infinite recovery loop caused by SQLite replaying the stale WAL against a freshly created database
  • Track the resolved AionUIDatabase instance synchronously (dbResolved) so closeDatabase() can be called from process.on('exit') handlers without needing to await a Promise
  • Add isShuttingDown guard to prevent re-entrant shutdown on double signal (e.g. two CTRL+C)
  • Call closeDatabase() explicitly in the shutdown() handler before closing the server, with process.on('exit') as a final safety net

Test plan

  • Start the server, then send SIGTERM/SIGINT — verify clean shutdown logs and no leftover -wal/-shm files
  • Send a second CTRL+C during shutdown — verify it force-exits without crashing or hanging
  • Simulate a corrupted DB (copy a bad file to the DB path) — verify recovery succeeds without infinite loop and WAL sidecars are cleaned up
  • Verify existing unit tests pass (bun run test)

- Remove stale WAL (-wal) and shared-memory (-shm) sidecar files
  during DB recovery to prevent infinite recovery loop on next start
- Track resolved DB instance synchronously so closeDatabase() can
  close the connection from process.on('exit') handlers (no await)
- Add isShuttingDown guard to prevent re-entrant shutdown on double signal
- Call closeDatabase() explicitly in shutdown() before server close,
  and as a safety net in process.on('exit')
@IceyLiu IceyLiu merged commit 4b57fd0 into main Mar 25, 2026
15 of 17 checks passed
@piorpua piorpua deleted the zynx/fix/db-graceful-shutdown branch March 25, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants