[spark-compete] fix: close SQLite database gracefully on SIGINT/SIGTERM - #839
Open
binance1230 wants to merge 1 commit into
Open
[spark-compete] fix: close SQLite database gracefully on SIGINT/SIGTERM#839binance1230 wants to merge 1 commit into
binance1230 wants to merge 1 commit into
Conversation
SIGINT/SIGTERM handlers did not close the SQLite database, risking WAL corruption on unclean shutdown. Add closeJsonState() that checkpoints the WAL and closes the connection, then call it from both signal handlers.
NoRegretz
pushed a commit
to NoRegretz/spark-telegram-bot
that referenced
this pull request
Jul 1, 2026
vibeforge1111#839: add closeJsonState() — checkpoint the WAL (TRUNCATE) and close the better-sqlite handle, best-effort and idempotent (nulls db, early-returns when already closed). Call it from the SIGINT and SIGTERM handlers so a shutdown flushes and releases the DB instead of leaving a -wal/-shm behind. Per maintainer note, added a small unit test asserting closeJsonState() is idempotent, nulls the handle, and that state reopens lazily on the next read. PRs: vibeforge1111#839 Co-authored-by: binance1230 <binance1230@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
{ "schema": "spark-compete-hotfix-v1", "event": "spark-compete-first-event", "submission_mode": "public_repo_pr", "submission_target_url": "https://github.com/vibeforge1111/spark-telegram-bot/pull/839", "team": { "name": "king", "members": [ "@king1005678", "@AtwoodJonathan1", "@JaredAddison12" ], "llm_device_holder": "@king1005678", "device_holder_github": "binance1230", "github_accounts": [ "binance1230" ] }, "target_repo": { "id": "vibeforge1111/spark-telegram-bot", "source": "https://github.com/vibeforge1111/spark-telegram-bot", "owner_surface": "telegram-bot" }, "issue": { "type": "bug", "severity": "high", "title": "SQLite database not closed on SIGINT/SIGTERM \u2014 risks WAL corruption", "actual_behavior": "SIGINT/SIGTERM handlers call releaseGatewayOwnership and stop the bot, but do not close the SQLite database. This risks WAL corruption on unclean shutdown.", "expected_behavior": "On shutdown signals, the database should be gracefully closed: checkpoint the WAL, then close the connection.", "repro_steps": [ "1. Start the bot and let it open the SQLite database.", "2. Send SIGINT or SIGTERM to the process.", "3. Observe that the database is not closed \u2014 the WAL file may be left in an inconsistent state." ], "affected_workflow": "Telegram bot shutdown and data integrity" }, "evidence": { "safe_links_only": true, "before_after_proof": "Before: SIGINT/SIGTERM handlers do not close SQLite. After: closeJsonState() checkpoints WAL and closes the connection before the process exits.", "links": [ "https://github.com/vibeforge1111/spark-telegram-bot/pull/839" ], "forbidden": [ "No raw logs, private conversations, secrets, tokens, screenshots of private chats, or archive downloads." ] }, "proposed_fix": { "approach": "Add closeJsonState() function that checkpoints WAL (PRAGMA wal_checkpoint(TRUNCATE)) and closes the SQLite connection. Call it from both SIGINT and SIGTERM signal handlers.", "files_expected": [ "src/jsonState.ts", "src/index.ts" ], "tests_or_smoke": "smoke_test: sending SIGINT/SIGTERM triggers closeJsonState() which checkpoints WAL and closes the db" }, "pr": { "url": "https://github.com/vibeforge1111/spark-telegram-bot/pull/839", "branch": "fix/db-graceful-shutdown", "title_prefix": "[spark-compete]", "author_github": "binance1230", "body_must_include": [ "packet", "team", "pr_author", "repo", "actual_behavior", "expected_behavior", "repro_steps", "before_after_proof", "tests_or_smoke", "duplicate_notes", "risk_notes", "review_claim" ], "replaces_url": "https://github.com/vibeforge1111/spark-telegram-bot/pull/87" }, "review_claim": { "impact_claim": "high", "evidence_types": [ "smoke_test", "redacted_conversation_excerpt" ], "duplicate_notes": "Replaces #87 (which contained stacked fixes). This PR addresses only the DB shutdown root cause.", "risk_notes": "Low risk: closeJsonState() is best-effort with try/catch/finally. If database is not open, it returns immediately. No behavioral change to normal operation.", "review_state_requested": "pr_review" } }