Skip to content

🐛 fix(rw): dispatch signals while SQLite waits - #1105

Merged
gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:fix/rw-signal-busy-wait
Nov 21, 2026
Merged

gaborbernat merged 3 commits into
tox-dev:mainfrom
gaborbernat:fix/rw-signal-busy-wait

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

A single-threaded process waiting for a ReadWriteLock can run its Python signal handlers while another process still holds the database. A shutdown handler that raises stops the acquisition and releases the waiting connection. Previously the handler could wait until SQLite acquired the lock or the caller's timeout expired (#1027).

The waiter asks SQLite to wait up to 100 ms at a time and charges elapsed time against the acquisition timeout. A single-threaded synchronous writer that needs another attempt keeps its pending lock on the same connection. Existing readers can finish, and later readers wait behind the writer. A multithreaded process on a system with fork support still releases its connection between attempts so another thread can fork.

Fixes #1027.

Return to Python during a contended SQLite acquisition. Reserve the writer
slot before retaining locks across retries so an existing writer can finish
and later readers stay behind a pending writer.

Fixes tox-dev#1027
PyPy can leave an executescript statement open when a Python signal handler
raises during sqlite3_step. Its connection tracks statements from execute
and finalizes them on close, releasing a pending writer even after a signal.
@gaborbernat
gaborbernat force-pushed the fix/rw-signal-busy-wait branch from 4e0fd90 to 986291d Compare November 21, 2026 03:18
@gaborbernat
gaborbernat marked this pull request as ready for review November 21, 2026 04:20
@gaborbernat
gaborbernat merged commit 4850cb6 into tox-dev:main Nov 21, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single-threaded ReadWriteLock wait defers signal handlers

1 participant