Repository navigation
Fix transient startable components never being stopped on container dispose (#79) - #680
Open
haraldrohan wants to merge 1 commit into
Open
haraldrohan wants to merge 1 commit into
haraldrohan wants to merge 1 commit into
Conversation
…ispose (castleproject#79) The StartableFacility resolved startable components with an empty CreationContext, which uses a NoTrackingReleasePolicy. Components that are not kept by their lifestyle (transient ones) were therefore never tracked by the container and were never stopped or disposed with it. Resolve them using the release policy of the kernel instead. 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 #79
Problem
A transient component started by the
StartableFacilityis never stopped or disposed when the container is disposed. For a singleton the container callsStop()andDispose(); for a transient onlyStart()is ever called (see the test results in the issue).Cause
The facility resolves startable components with
CreationContext.CreateEmpty(), which uses aNoTrackingReleasePolicy. Components that are not kept by their lifestyle (transient ones) are therefore never tracked by the container's release policy, so nothing decommissions them on dispose.Fix
StartFlaggets a protectedCreateContext()that creates the empty context and sets the release policy of the kernel on it. All places that started components use it:StartFlag.Start,DeferredTryStartFlagandLegacyStartFlag, so every start mode is covered.Notes
StartFlag.CreateContext()is a new protected member on a public class.Stop()andDispose()to be called at all. They were previously not tracked, so this changes their memory behaviour: they stay alive until the container is disposed.events.Kernelis not anIKernelthe old behaviour is kept. In practice it always is the kernel.Tests
New
LoggingStartableTestCasechecks that a transient startable logsstart, stop, disposewhen the container is disposed, for the default (legacy) mode,DeferredStart,DeferredTryStartand a manually signalledStartFlag. These four failed before the fix (onlystartwas logged). A singleton case is included as a control and passed before.Castle.Windsor.Tests(net6.0): 1255 passed, 0 failed. I did not run the net462 target.Added a
CHANGELOG.mdentry. It creates theUnreleasedsection, as does #679, so those two will conflict trivially in the changelog.🤖 Generated with Claude Code