Skip to content

The timeout setting is not honored when a transaction is active (with example) #124510

Closed as not planned
@jogc

Description

@jogc

Bug report

Bug description:

The timeout argument to sqlite3.connect is not honored and a "sqlite3.OperationalError: database is locked" is triggered immediately if this script is invoked a second time while the first is still running (sleeping). This only happens when a
transaction is active - if the BEGIN statement is removed the bug is not triggered.

Expected behavior: the script should wait for up to 10 seconds for the first invocation to finish before giving up
Actual behavior: the script immediately crashes with "sqlite3.OperationalError: database is locked"

Python version: 3.11.2 (Debian: python3.11-minimal 3.11.2-6+deb12u3, libpython3.11-stdlib:amd64 3.11.2-6+deb12u3)
SQLite version: 3.40.1 (Debian: sqlite3 3.40.1-2)
OS: Debian GNU/Linux 12.7
Kernel: Linux 6.1.0-22-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.94-1 (2024-06-21) x86_64 GNU/Linux

#
# a table must be manually created first:
#   sqlite3 testcase.db 'CREATE TABLE IF NOT EXISTS customers (a)'
# (if this is done by the script the bug is not triggered for some reason)
#

import sqlite3
import time

conn = sqlite3.connect(
    'testcase.db',
    isolation_level = None, # test case will work even if this is left out
    timeout = 10
)

c = conn.cursor()

print('starting transaction')
c.execute('''BEGIN''')
print('transaction started')

print('doing SELECT')
c.execute('SELECT * FROM customers', ())
print('did SELECT')

print('doing UPDATE')
c.execute('UPDATE customers SET a = 0 WHERE a = 999999', ())
print('did UPDATE')

print('sleeping')
time.sleep(30)
print('slept')

print('transaction ended')

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions