Skip to content

fix: enable SQLite WAL mode to prevent locks (#493)#509

Merged
aaronbrethorst merged 1 commit intoOneBusAway:mainfrom
ARCoder181105:fix/493-enable-sqlite-wal-mode
Mar 1, 2026
Merged

fix: enable SQLite WAL mode to prevent locks (#493)#509
aaronbrethorst merged 1 commit intoOneBusAway:mainfrom
ARCoder181105:fix/493-enable-sqlite-wal-mode

Conversation

@ARCoder181105
Copy link
Copy Markdown
Contributor

Description

This PR addresses issue #493 by explicitly enabling Write-Ahead Logging (WAL) for SQLite databases.

Previously, WAL mode was referenced in the connection pool comments but was never actually applied in the database configuration. Without WAL mode, SQLite falls back to the default rollback journal where readers block writers and writers block readers. With MaxOpenConns set to 25 for file-based databases, this would inevitably lead to database is locked errors under concurrent production load.

Changes Made

  • gtfsdb/helpers.go: Added PRAGMA journal_mode=WAL to the configureSQLitePerformance function to allow concurrent readers and a single writer.
  • gtfsdb/sqlite_performance_test.go:
    • Updated TestFileDatabaseConnectionPool to verify that wal mode is properly enabled for file-based databases.
    • Updated TestSQLitePerformancePragmasApplied to verify that :memory: databases safely fall back to memory journal mode (as SQLite does not support WAL in-memory).

Related Issues

Closes #493

Checklist

  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Aditya -- Clean and surgical fix. The configureConnectionPool comments have been referencing WAL mode since the connection pool was set up, but the PRAGMA was never actually applied. This PR closes that gap with minimal, correct code and appropriate test coverage.


No Issues Found

The change is correct:

  • PRAGMA journal_mode=WAL is a database-level persistent setting for file-based databases, so it correctly applies across all pooled connections.
  • For :memory: databases, SQLite silently falls back to memory journal mode (no error), which is the right behavior since the connection pool is already limited to 1 for in-memory databases.
  • The test assertions verify both cases: "wal" for file databases, "memory" for in-memory databases.

Verification

  • Tests: all pass
  • Lint: 0 issues
  • Single commit: clean

Strengths

  • Minimal and focused: 2 lines of production code, exactly what was needed.
  • Both cases tested: File-based databases get WAL mode verified, in-memory databases get the fallback behavior verified.
  • Accurate comments: The inline comment correctly describes what WAL mode provides.

Looks good -- merge it!

@aaronbrethorst aaronbrethorst merged commit 432ce91 into OneBusAway:main Mar 1, 2026
4 checks passed
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.

SQLite WAL mode not enabled — will cause database lock errors under load

2 participants