Skip to content

Fix transient startable components never being stopped on container dispose (#79) - #680

Open
haraldrohan wants to merge 1 commit into
castleproject:masterfrom
haraldrohan:fix-79-transient-startable-not-stopped
Open

haraldrohan wants to merge 1 commit into
castleproject:masterfrom
haraldrohan:fix-79-transient-startable-not-stopped

Conversation

@haraldrohan

Copy link
Copy Markdown

Fixes #79

Problem

A transient component started by the StartableFacility is never stopped or disposed when the container is disposed. For a singleton the container calls Stop() and Dispose(); for a transient only Start() is ever called (see the test results in the issue).

Cause

The facility resolves startable components with CreationContext.CreateEmpty(), which uses a NoTrackingReleasePolicy. 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

StartFlag gets a protected CreateContext() that creates the empty context and sets the release policy of the kernel on it. All places that started components use it: StartFlag.Start, DeferredTryStartFlag and LegacyStartFlag, so every start mode is covered.

Notes

  • StartFlag.CreateContext() is a new protected member on a public class.
  • Transient startables are now tracked until the container is disposed, which is what allows Stop() and Dispose() to be called at all. They were previously not tracked, so this changes their memory behaviour: they stay alive until the container is disposed.
  • If events.Kernel is not an IKernel the old behaviour is kept. In practice it always is the kernel.

Tests

New LoggingStartableTestCase checks that a transient startable logs start, stop, dispose when the container is disposed, for the default (legacy) mode, DeferredStart, DeferredTryStart and a manually signalled StartFlag. These four failed before the fix (only start was 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.md entry. It creates the Unreleased section, as does #679, so those two will conflict trivially in the changelog.

🤖 Generated with Claude Code

…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>
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.

Never resolved transient startable component will not stop

1 participant