Repository navigation
🐛 fix(async): settle pending reader/writer acquires on close - #1073
Merged
gaborbernat merged 8 commits intoNov 21, 2026
Merged
Conversation
gaborbernat
marked this pull request as draft
November 20, 2026 15:32
gaborbernat
force-pushed
the
fix/async-table-close-wait-1061
branch
3 times, most recently
from
November 20, 2026 15:50
90b79e5 to
78d2106
Compare
gaborbernat
marked this pull request as ready for review
November 20, 2026 17:44
gaborbernat
marked this pull request as draft
November 20, 2026 19:33
gaborbernat
force-pushed
the
fix/mx-pid-namespace
branch
from
November 20, 2026 19:45
4668ddd to
8635548
Compare
gaborbernat
force-pushed
the
fix/async-table-close-wait-1061
branch
from
November 20, 2026 19:52
78d2106 to
47b6e4b
Compare
gaborbernat
marked this pull request as ready for review
November 20, 2026 21:37
gaborbernat
marked this pull request as draft
November 20, 2026 22:00
Closing one singleton wrapper left its pending acquires asleep when another wrapper held the lock. Associate each admission ticket with its wrapper so close can wake its own waiters, then check the wrapper state before admission. Fixes tox-dev#1061
A failed close could restore a backend hold after the waiting acquire had already raised the closed error. The task then had no proxy to release it. Wait for close to settle before resolving the acquire. On failure, the task keeps its hold. Cancellation releases it before reporting cancellation. Refs tox-dev#1022
A close could wait indefinitely behind a task waiting for another process to release the lock. Stop pending SQLite and soft lock acquires on their next backend poll. Fixes tox-dev#1016
Wake the first waiting writer when the lock is free. Keep its place until it enters or cancels so a returning writer cannot pass it.
A wait on one async soft read/write lock could occupy the event loop's default pool while another lock's release remained queued. Give each default wrapper an owned worker so the blocked wait cannot delay that release. Caller-supplied executors remain caller-owned and need enough capacity for concurrent waits and releases.
A pending backend acquire owns no task holds. Let another singleton wrapper close without waiting for that acquire. Keep waiting when the closing wrapper started the acquire or owns the backend.
gaborbernat
force-pushed
the
fix/async-table-close-wait-1061
branch
from
November 20, 2026 23:58
f18a9bb to
00834b9
Compare
gaborbernat
marked this pull request as ready for review
November 21, 2026 00:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closing an async reader/writer lock could stall behind its own pending acquire or let that acquire return a hold that close had already released. Both SQLite and soft locks now wake tasks waiting through the closing wrapper and interrupt contended backend acquires at their next poll. A singleton wrapper can close while another wrapper continues its backend acquire. On successful close, tasks waiting through the closed SQLite wrapper receive
sqlite3.ProgrammingErrorand those waiting through the closed soft wrapper receiveRuntimeError. #1061, #1016A task that obtains a lock while its own wrapper is closing waits for the outcome. If close releases the hold, the acquire raises the wrapper's closed error. If close fails with the hold intact, the task receives its hold and can release it. #1022
flowchart TD Grant["Backend grants the lock during close"] --> Close{"Did close release the hold?"} Close -->|Yes| Closed["Acquire raises the closed error"] Close -->|No| Held["Acquiring task keeps the hold"] classDef state fill:#cfe4ff,stroke:#1f6feb,color:#0b1f3a classDef result fill:#d8ecd5,stroke:#387a42,color:#0b1f3a class Grant,Close state class Closed,Held resultAsync wrappers that share a lock instance in one process grant queued writers access in arrival order. New readers wait behind those writers. If the first writer's event loop pauses, the queue waits for it to resume. #1017
Each soft wrapper uses its own worker by default, so a blocked acquire on one lock leaves a worker available to release another. Successful close waits for that worker to exit. If you supply an executor shared by wrappers, leave a worker available for releases and shut down the executor yourself. #1037
Fixes #1061, fixes #1016, fixes #1022, and fixes #1017.