Skip to content

Fix AddCallback deadlock under concurrent transactions - #121

Merged
krauthaufen merged 1 commit into
masterfrom
fix/callback-deadlock-120
Sep 21, 2026
Merged

krauthaufen merged 1 commit into
masterfrom
fix/callback-deadlock-120

Conversation

@krauthaufen

Copy link
Copy Markdown
Collaborator

Fixes #120.

MultiCallbackObject.check took the callback-table lock while the object's own monitor was already held (Mark runs under the transaction's EnterWrite, remove under lock x), whereas setMultiCallback takes the table lock first and then enters the object in Subscribe. With one thread transacting and another adding/disposing callbacks, the two orders deadlock.

check now uses Monitor.TryEnter on the table: if contended it skips the self-release and stays subscribed; the next Mark/remove retries. Worst case is one empty callback object per adaptive object lingering until the next transaction or subscription on it.

Tests: regression test from the issue's repro (deadlocked the host before, ~1 s now), plus a deterministic test forcing the contended path and asserting the lingering object is reused correctly by a new subscription and released by the next marking. Full suite green.

MultiCallbackObject.check blocked on the callback-table lock while holding the object's monitor, the reverse of setMultiCallback's order. Release now uses Monitor.TryEnter and retries on the next Mark/remove when contended.
@krauthaufen
krauthaufen merged commit 6209087 into master Sep 21, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AddCallback causes deadlock

1 participant