Repository navigation
🐛 fix(async): stop queued calls after submit fails - #986
Merged
gaborbernat merged 1 commit intoNov 20, 2026
Merged
Conversation
A thread pool can queue a release before failing to start a worker. The failed release must not run after another task enters the retained hold. Gate each backend call so a failed submission cancels work still queued, while a worker that already started can settle the lock state.
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.
run_in_executortreated an exception from executor submission as proof that its backend call would never run. In applications that reuse an async lock instance across tasks, a thread pool can queue a release and then fail to start a worker. The release can run after a later task enters while the lock state still reports held, allowing another process to acquire the same lock. This change stops queued backend calls after a failed submission and settles calls that already started. This addresses draft advisory ANT-2026-BZ7APGNK.Submission can fail after queuing
ThreadPoolExecutor.submitplaces work in its queue before it tries to start another worker.AsyncFileLockpreviously let a submission exception leave the hold in place while the queued release remained runnable. The read-write wrappers used the same submission pattern inAsyncReadWriteLock._submitandAsyncSoftReadWriteLock._submit.The new
submit_callgives the worker a one-shot claim before it runs the backend call. If submission fails while the call is queued, the caller cancels that claim. If the worker already started, the worker records its result in the claim, and the wrapper uses that result to update the lock state. All three async lock implementations now use this helper.sequenceDiagram participant C as Async caller participant P as Executor pool participant W as Worker participant N as Later task C->>+P: Submit release rect rgb(255, 214, 214) P-->>C: Worker start fails after queueing N->>N: Enter retained hold P->>+W: Run queued release W-->>-P: Unlock under later task end deactivate P rect rgb(216, 243, 220) C->>+P: Fixed submission with claim P-->>C: Worker start fails after queueing C->>C: Cancel unstarted claim P->>+W: Take queued call W-->>-P: Skip backend release deactivate P endBehavior changes
When submission raises before a worker begins, the caller still gets the submission error and the backend call does not run later. If a worker began before submission raised, the async operation now returns or raises according to the backend outcome. A failed release still leaves the hold for the caller to retry. The fix covers the default event-loop pool and custom executors used by the three async lock classes.
Reported in the filelock scan: ANT-2026-BZ7APGNK.