Skip to content

fix(db): harden sqlite pragmas and dispose engine cleanly#125

Closed
mojomast wants to merge 1 commit intofollowup/pr124-auth-securityfrom
followup/pr125-db-hardening
Closed

fix(db): harden sqlite pragmas and dispose engine cleanly#125
mojomast wants to merge 1 commit intofollowup/pr124-auth-securityfrom
followup/pr125-db-hardening

Conversation

@mojomast
Copy link
Collaborator

@mojomast mojomast commented Feb 14, 2026

Summary

  • apply SQLite runtime pragmas on each connection (WAL, synchronous=NORMAL, temp_store=MEMORY, foreign_keys=ON, configured busy_timeout)
  • add SQLITE_BUSY_TIMEOUT_MS support and set engine connect timeout accordingly for better write contention behavior
  • split DB runtime init to return engine + session maker and dispose the engine during app shutdown
  • document new SQLite timeout setting in .env.example and README.md

Verification

  • PYTHONPATH=src .venv/bin/python -m py_compile src/proxy_app/db.py src/proxy_app/main.py tests/test_db_runtime.py
  • PYTHONPATH=src .venv/bin/pytest -q tests/test_db_runtime.py

Important

Enhance SQLite handling by applying runtime pragmas, introducing a configurable busy timeout, and ensuring clean engine disposal.

  • SQLite Configuration:
    • Apply runtime pragmas (WAL, synchronous=NORMAL, temp_store=MEMORY, foreign_keys=ON, busy_timeout) on each connection in db.py.
    • Introduce SQLITE_BUSY_TIMEOUT_MS environment variable for configuring SQLite busy timeout.
  • Database Initialization:
    • Split DB runtime initialization in db.py to return engine and session maker separately.
    • Dispose of the engine during app shutdown in main.py.
  • Documentation:
    • Document SQLITE_BUSY_TIMEOUT_MS in .env.example and README.md.
  • Testing:
    • Add test_sqlite_pragmas_are_applied in test_db_runtime.py to verify SQLite pragmas are correctly applied.

This description was created by Ellipsis for 4365eed. You can customize this summary. It will automatically update as commits are pushed.

@mojomast mojomast requested a review from Mirrowel as a code owner February 14, 2026 03:23
@mojomast
Copy link
Collaborator Author

Superseded by updates pushed to #123 to keep all MVP changes in one review thread.

@mojomast mojomast closed this Feb 14, 2026
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.

1 participant