Skip to content

Allow configuring the SQLite busy timeout (SQLITE_BUSY_TIMEOUT) #548

Open

Description

@chubes4

WP_SQLite_Connection already accepts a timeout option, which sets PDO::ATTR_TIMEOUT (SQLite's busy timeout). The default is DEFAULT_SQLITE_TIMEOUT = 10. The plugin never passes that option, though: WP_SQLite_DB::db_connect() and install-functions.php forward only sqlite_journal_mode. As a result, a site can't change how long a connection waits for the write lock.

Why it matters: hosts that run several PHP workers against one database file get concurrent writers. Each write runs as its own short BEGIN IMMEDIATE, so they take turns without trouble. When one request holds a write transaction for longer than the busy timeout, though, every other writer fails with SQLSTATE[HY000]: General error: 5 database is locked instead of waiting. Examples are a slow migration or a plugin doing work inside an explicit transaction. Reproduced with WordPress Studio's native PHP worker pool: one request held a write transaction for 45s, and a concurrent wpdb->insert() in another worker failed. With a 12s or 20s hold, the second write waited and succeeded. Development hosts would rather wait longer than error.

Proposal: follow the SQLITE_JOURNAL_MODE pattern:

  • Add a sqlite_timeout driver option to WP_MySQL_On_SQLite, forwarded to the connection's timeout.
  • Read an optional SQLITE_BUSY_TIMEOUT constant (whole seconds) in the plugin's two connection sites.
  • Leave the default unchanged.

Related: #318.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions