Conversation
Property observation attached PropertyChanged handlers and emitted the initial value from the subscription constructor, so a failure during initialization escaped before Observable.Create could return a disposable. Every handler installed on the way in stayed attached, leaking the observed objects. Ownership is now established before activation: the subscription is constructed, scoped by a RefCountDisposable, and only started afterwards. Rx receives a dependent lease only once activation succeeds, so a throwing getter or subscriber callback releases every handler at every chain level while the original exception still propagates unchanged.
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.
Problem
WhenPropertyChanged/WhenValueChangedattachedPropertyChangedhandlers and emitted the initial value from the subscription's constructor. If anything threw during that work (a property getter, or a subscriber callback receiving the initial value), the exception escaped beforeObservable.Createcould hand back a disposable. Rx had nothing to dispose, so every handler installed on the way in stayed attached and kept the observed objects alive.Fix: ownership before activation
The subscription object is now constructed first, scoped by a
RefCountDisposable, and only then started:The scope owns initialization. If
Startthrows, theusingreleases the subscription and detaches every handler attached so far, at every level of a deep chain. Only successful activation hands a dependent lease to Rx. The original exception still propagates unchanged, and subscriber callback failures are never converted intoOnError.Both the shallow single-property path and the deep-chain path are covered;
DeepChainSubscriptiongains the sameStart()seam so its chain walk runs under the same ownership scope.Tests
WhenPropertyChangedBehaviorFixture.Initialization.csadds regression coverage for a throwing initial observer, a throwing getter under both the default and a handled error path, shallow and deep chains, explicit disposal, and synchronous completion viaTake(1). Each asserts handler counts drop to zero while confirming handlers attach before the value is read. Prior focused validation of these tests passed.Fixes #1176