Skip to content

🐛 fix(soft): relinquish fd before close#649

Merged
gaborbernat merged 1 commit into
mainfrom
fix/633-soft-close-ownership
Jul 14, 2026
Merged

🐛 fix(soft): relinquish fd before close#649
gaborbernat merged 1 commit into
mainfrom
fix/633-soft-close-ownership

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Jul 14, 2026

Copy link
Copy Markdown
Member

SoftFileLock left its descriptor recorded as held until os.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's os.close() implementation and the Linux close(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_policy now governs soft-lock close errors while preserving its historical default behavior. 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.

@gaborbernat gaborbernat force-pushed the fix/633-soft-close-ownership branch from b72ab8b to de170fa Compare July 14, 2026 02:52
@gaborbernat gaborbernat marked this pull request as ready for review July 14, 2026 02:57
Base automatically changed from fix/631-detach-release-context to main July 14, 2026 04:05
@gaborbernat gaborbernat marked this pull request as draft July 14, 2026 04:09
@gaborbernat gaborbernat force-pushed the fix/633-soft-close-ownership branch from de170fa to 8d55c4e Compare July 14, 2026 04:12
@gaborbernat gaborbernat marked this pull request as ready for review July 14, 2026 04:15
@gaborbernat gaborbernat enabled auto-merge (squash) July 14, 2026 04:15
@gaborbernat gaborbernat marked this pull request as draft July 14, 2026 04:41
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.
@gaborbernat gaborbernat force-pushed the fix/633-soft-close-ownership branch from 8d55c4e to 36096c3 Compare July 14, 2026 05:17
@gaborbernat gaborbernat marked this pull request as ready for review July 14, 2026 05:27
@gaborbernat gaborbernat merged commit fe8b46d into main Jul 14, 2026
36 checks passed
@gaborbernat gaborbernat deleted the fix/633-soft-close-ownership branch July 14, 2026 07:30
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.
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.

Prevent SoftFileLock from retrying an ambiguous close

1 participant