🐛 fix(soft): relinquish fd before close#649
Merged
Merged
Conversation
b72ab8b to
de170fa
Compare
de170fa to
8d55c4e
Compare
auto-merge was automatically disabled
July 14, 2026 04:41
Pull request was converted to draft
SoftFileLock kept the descriptor in held state until os.close returned. A close error left that integer retryable, so a later release could close an unrelated file after descriptor reuse. Clear ownership before the single close attempt. Marker cleanup uses captured identity even when close fails, and close_error_policy controls whether that error propagates. Group a concurrent cleanup failure so neither error is lost.
8d55c4e to
36096c3
Compare
gaborbernat
added a commit
that referenced
this pull request
Jul 14, 2026
Executor-backed lock operations can outlive the task awaiting them. Keep the backend future alive after caller cancellation, drain it, and compensate any acquisition that completed after cancellation before propagating the caller’s error. Serialize provisional acquisition and release transitions on each async lock. This prevents one caller’s rollback from releasing a descriptor acquired by another caller while preserving each queued caller’s nonblocking, timeout, and `cancel_check` policy. Release cancellation now preserves backend failures according to the lock's context-error policy. Async SQLite read-write locks use the same cancellation boundary and retain transaction state until rollback ends the transaction. A later acquisition or forced release can retry cleanup. PR #649 establishes the descriptor-ownership rules that cancellation reconciliation uses, so this branch targets it. Fixes #640.
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.
SoftFileLockleft its descriptor recorded as held untilos.close()returned. A failed close can still retire the descriptor, so a later release could close an unrelated file after the OS reused the integer. Issue #633 documents this ambiguity; CPython'sos.close()implementation and the Linuxclose(2)notes explain why callers must not retry.The release clears descriptor ownership before one close attempt, captures marker identity first, and performs marker cleanup even when close fails.
close_error_policynow governs soft-lock close errors while preserving its historicaldefaultbehavior. If close and cleanup both fail, the release keeps them as sibling errors under the grouped-failure contract from #648.Existing call signatures and defaults remain compatible. The branch builds on #648, which should merge first. Closes #633.