Skip to content

Fix re-entrant resolve deadlock (issue #4)#6

Merged
robert-northmind merged 1 commit into
mainfrom
claude/investigate-issue-vHP4J
Mar 31, 2026
Merged

Fix re-entrant resolve deadlock (issue #4)#6
robert-northmind merged 1 commit into
mainfrom
claude/investigate-issue-vHP4J

Conversation

@robert-northmind

@robert-northmind robert-northmind commented Mar 31, 2026

Copy link
Copy Markdown
Owner

Calling pod.resolve() from within a provider builder that holds a
reference to the same SwiftiePod instance (e.g. via a global Log
shim) caused a deadlock: the outer resolve held dispatchQueue via
sync, and the inner resolve attempted another sync on the same
serial queue.

Fix: use DispatchSpecificKey to mark the queue context. Before
calling dispatchQueue.sync, check whether the current execution
context is already on the queue. If so, invoke the resolver directly
— the serial queue guarantees exclusive access, so this is safe.

Also adds ReentrantResolveTests.swift with three tests that cover
the safe path (using the passed-in resolver), the direct re-entrant
path from the issue reproduction, and the real-world Log-shim scenario.

Calling `pod.resolve()` from within a provider builder that holds a
reference to the same `SwiftiePod` instance (e.g. via a global `Log`
shim) caused a deadlock: the outer `resolve` held `dispatchQueue` via
`sync`, and the inner resolve attempted another `sync` on the same
serial queue.

Fix: use `DispatchSpecificKey` to mark the queue context. Before
calling `dispatchQueue.sync`, check whether the current execution
context is already on the queue. If so, invoke the resolver directly
— the serial queue guarantees exclusive access, so this is safe.

Also adds `ReentrantResolveTests.swift` with three tests that cover
the safe path (using the passed-in resolver), the direct re-entrant
path from the issue reproduction, and the real-world Log-shim scenario.

https://claude.ai/code/session_017ztecAXmWm6cLm5rmPuAX2
@robert-northmind
robert-northmind merged commit fc6a15c into main Mar 31, 2026
2 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.

2 participants