Repository navigation
Fix disposable transient dependencies being disposed twice on container dispose (#600) - #679
Open
haraldrohan wants to merge 1 commit into
Conversation
…er dispose (castleproject#600) LifecycledComponentsReleasePolicy.Dispose released every tracked burden. A transient root and its transient dependencies are all tracked, and releasing the root also releases the burdens of its dependencies, so those dependencies were released a second time through their own entry. Skip burdens that were already released as part of another burden's graph. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Fixes #600
Problem
When a container is disposed, a disposable transient component that was resolved as a dependency of another transient component gets
Dispose()called twice. This is independent ofUsingFactoryMethod(the issue's repro uses it, but a plain registration behaves the same); it only needs a transient root with a disposable transient dependency.Cause
LifecycledComponentsReleasePolicy.Dispose()takes a snapshot of all tracked burdens and releases each one. The root and its dependency are both tracked, and releasing the root's burden also releases the burdens of its dependencies. The dependency is then released a second time through its own entry in the snapshot.An explicit
container.Release(root)is not affected, because the dependency is removed from the policy's tracking when it is released as part of the root's graph.Fix
While disposing, remember which burdens were already released as part of another burden's graph and skip them. The dictionary is still cleared up front and the tracked-instances counter is decremented as before, so nothing else changes.
Tests
Added to
LifecycledComponentsReleasePolicyComponentTrackingTestCase:UsingFactoryMethod, matching the issue (failed before with 2 instead of 1)Castle.Windsor.Tests(net6.0): 1253 passed, 0 failed.Castle.Windsor.Extensions.DependencyInjection.Tests(net6.0): 171 passed. I did not run the net462 target.Added a
CHANGELOG.mdentry under a newUnreleasedsection.The fix relies on a dependency being tracked before its parent, which always holds today and which
Dispose()already assumes for its release order.🤖 Generated with Claude Code