Detect re-entrant self-cycle via direct pod reference (issue #5) + v1.1.3#7
Merged
Merged
Conversation
When a provider's builder calls pod.resolve() on itself (via a captured global pod reference), the fix from issue #4 prevented a deadlock but left an infinite recursion / stack overflow unhandled. Fix: track which providers have an actively-running builder in a Set<ObjectIdentifier> on SwiftiePod (currentlyBuildingProviders). This set is maintained via onBuildStart/onBuildEnd callbacks threaded through InternalProviderResolver and called around every provider.build() call. The re-entrant fast-path in SwiftiePod.resolve checks this set and calls cyclicDependencyHandler if the same provider is already building. Adds testReentrantSelfCycleIsDetected to ReentrantResolveTests, following the same thread-blocking pattern used by the existing cyclic dependency test. https://claude.ai/code/session_017ztecAXmWm6cLm5rmPuAX2
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.
$(cat <<'EOF'
Summary
Closes #5.
pod.resolve()on itself via a direct pod reference is now detected as a cyclic dependency and reported viacyclicDependencyHandler, instead of causing infinite recursion and a stack overflow.InternalProviderResolvernow accepts optionalonBuildStart/onBuildEndcallbacks that fire around everyprovider.build(...)call.SwiftiePodmaintains aSet<ObjectIdentifier>(currentlyBuildingProviders) via these callbacks, and checks it in the re-entrant fast-path before proceeding.1.1.2→1.1.3(podspec + CHANGELOG).Performance impact
Negligible — the callbacks only fire on cache misses. Singleton providers pay the cost once ever;
AlwaysCreateNewScopeproviders pay two closure calls + two O(1) Set operations per resolve, which is dwarfed by the builder execution anddispatchQueue.syncoverhead.Test plan
testReentrantSelfCycleIsDetected— new test inReentrantResolveTests: verifies that a self-referential re-entrant provider triggerscyclicDependencyHandlerwith the expected messagenil, so no existing behaviour changes)swift test, ExampleApp build, iOS simulator build + testsEOF
)