Skip to content

🐛 fix(api): roll back interrupted acquisitions - #1060

Merged
gaborbernat merged 4 commits into
mainfrom
fix/ynl-counter-signal-agent
Nov 20, 2026
Merged

gaborbernat merged 4 commits into
mainfrom
fix/ynl-counter-signal-agent

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

An exception during acquire() could leave the caller holding a lock it never received (#1030). Synchronous and asynchronous acquires now roll back the new hold. If rollback fails, the acquire reports the cleanup error and retains the hold for an explicit release(). A failed nested acquire restores the earlier depth. Fixes #1030.

During a synchronous acquire, a hook or signal handler may enter and leave its own nested with lock: block. Releasing the level that the interrupted acquire is taking raises RuntimeError. A forced release drops every level, and the interrupted acquire raises RuntimeError if it observes that release. Fixes #1071. Fixes #1076.

flowchart TD
    A["First acquire starts"] --> B["Backend takes lock"]
    B --> C{"Hook completes?"}
    C -->|Yes| D["Return hold to caller"]
    C -->|Raises| E["Roll back provisional hold"]
    E --> F{"Unlock succeeds?"}
    F -->|Yes| G["Peer can acquire"]
    F -->|No| H["Caller can retry release"]
    classDef step fill:#cfe4ff,stroke:#1f6feb,color:#0b1f3a
    classDef decision fill:#ffe3a3,stroke:#d29200,color:#3a2c00
    class A,B,D,E,G,H step
    class C,F decision
Loading

An interrupted release checks that it still owns the same hold before retrying. A waiter also checks whether its own signal handler acquired another instance on the same path before sleeping again. This lets it report a deadlock while the handler's hold is still live. Fixes #1004. Fixes #1083.

The original count error was reported as ANT-2026-YNLBMYLA.

A callback can interrupt the acquire after the backend takes the lock.
Restore the previous depth on failure and refuse a release that would
consume the level still being acquired.

Fixes #1030
Fixes #1071
Fixes #1076
An interrupted release can resume after another thread has acquired the
lock at the same depth. Check the acquisition generation under the
transition gate before retrying.

Fixes #1004
A signal handler can acquire a peer after the initial deadlock check.
Check the pinned path again before waiting on that peer.

Fixes #1083
@gaborbernat
gaborbernat force-pushed the fix/ynl-counter-signal-agent branch from 77e4142 to c2e7855 Compare November 20, 2026 15:39
@gaborbernat gaborbernat changed the title 🐛 fix(api): restore count after failed acquire 🐛 fix(api): roll back interrupted acquisitions Nov 20, 2026
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 17:33
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 19:33
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 21:28
@gaborbernat
gaborbernat merged commit 2c1699d into main Nov 20, 2026
49 checks passed
@gaborbernat
gaborbernat deleted the fix/ynl-counter-signal-agent branch November 20, 2026 22:01
@gaborbernat
gaborbernat restored the fix/ynl-counter-signal-agent branch November 20, 2026 22:03
@gaborbernat
gaborbernat deleted the fix/ynl-counter-signal-agent branch November 20, 2026 22:03
gaborbernat added a commit that referenced this pull request Nov 20, 2026
Main contains the squashed acquisition changes from #1060. Use its
original head as the common base to keep the five hold-validation commits
from #1098.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant