Skip to content

SQLite plugin: respect config.SQL.MaxConns instead of hardcoding SetMaxOpenConns(1)#9730

Open
brucearctor wants to merge 1 commit intotemporalio:mainfrom
brucearctor:fix/sqlite-respect-maxconns-config
Open

SQLite plugin: respect config.SQL.MaxConns instead of hardcoding SetMaxOpenConns(1)#9730
brucearctor wants to merge 1 commit intotemporalio:mainfrom
brucearctor:fix/sqlite-respect-maxconns-config

Conversation

@brucearctor
Copy link
Copy Markdown

Summary

Fixes #9686

The SQLite plugin previously hardcoded db.SetMaxOpenConns(1) and db.SetMaxIdleConns(1), ignoring the config.SQL.MaxConns and config.SQL.MaxIdleConns fields. This caused all Temporal services (frontend, history, matching, worker) to serialize through a single database connection, leading to ShardIOTimeout failures at ~1000 concurrent workflows.

Changes

This change makes the SQLite plugin respect the user's connection pool configuration, consistent with the MySQL and PostgreSQL plugins:

Config Field Controls Default
cfg.MaxConns SetMaxOpenConns 1
cfg.MaxIdleConns SetMaxIdleConns 1
cfg.MaxConnLifetime SetConnMaxLifetime unset

Safety guardrails

  • WAL mode warning: A warning is logged if MaxConns > 1 without WAL mode (journal_mode=wal) enabled, since SQLite without WAL will encounter database is locked errors under concurrent access.
  • In-memory safety: For in-memory databases, ConnMaxIdleTime remains 0 (infinite) to prevent the database from being garbage collected when idle connections close.
  • Backward compatible: When MaxConns / MaxIdleConns are unset or 0, the plugin defaults to 1 — identical to current behavior.

Testing

  • Existing SQLite package tests pass (go test ./common/persistence/sql/sqlplugin/sqlite/...)
  • Build verified (go build ./common/persistence/sql/sqlplugin/sqlite/...)

…axOpenConns(1)

Fixes temporalio#9686

The SQLite plugin previously hardcoded db.SetMaxOpenConns(1) and
db.SetMaxIdleConns(1), ignoring the config.SQL.MaxConns and
config.SQL.MaxIdleConns fields. This caused all Temporal services to
serialize through a single database connection, leading to
ShardIOTimeout failures at ~1000 concurrent workflows.

This change makes the SQLite plugin respect the user's connection pool
configuration, consistent with the MySQL and PostgreSQL plugins:
- cfg.MaxConns controls SetMaxOpenConns (default: 1)
- cfg.MaxIdleConns controls SetMaxIdleConns (default: 1)
- cfg.MaxConnLifetime controls SetConnMaxLifetime

A warning is logged if MaxConns > 1 without WAL mode (journal_mode=wal)
enabled, since SQLite without WAL will encounter 'database is locked'
errors under concurrent access.

For in-memory databases, ConnMaxIdleTime remains 0 (infinite) to prevent
the database from being garbage collected when idle connections close.
@brucearctor brucearctor requested review from a team as code owners March 28, 2026 01:39
@gow gow requested a review from prathyushpv April 2, 2026 22:55
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 plugin: respect config.SQL.MaxConns instead of hardcoding SetMaxOpenConns(1)

1 participant