Skip to content

fix(operators): route callback faults to OnError - #248

Merged
glennawatson merged 1 commit into
mainfrom
fix/callback-exceptions-and-async-teardown
Nov 20, 2026
Merged

glennawatson merged 1 commit into
mainfrom
fix/callback-exceptions-and-async-teardown

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

Summary

This PR routes non-fatal user callback exceptions to downstream OnError across the remaining synchronous unary operators, fixes cross-thread disposal deadlocks in chained async witnesses and stop coordinators, and cleans up transitive NuGet package entries while updating dependencies.

  • Scan/Fold, Aggregate/Reduce, Do/Tap, DistinctUntilChanged/Unique, and DistinctUntilChangedBy/UniqueBy catch non-fatal callback exceptions, forward them to OnError, latch stopped state, and dispose upstream subscriptions across both live witnesses and synchronous sequence fast paths.
  • WitnessAsync, WitnessAsyncState, DisposableAsyncSlot, SingleAssignmentDisposableAsync, and the async stop coordinators propagate notification-context disposal to upstream subscriptions during in-flight notifications and completion teardown.
  • ParityOperatorTests.WhenDebounceUntil_WithConditionTrue_ThenEmitsImmediately uses ManualTimeProvider to verify immediate bypass emission without advancing time.
  • Central and project NuGet references drop unused and transitive-only pins and update TUnit, Microsoft.WindowsAppSDK, Microsoft.Extensions.TimeProvider.Testing (banded per target framework), and the .NET Framework BCL polyfill packages to their latest releases.

Why

User delegates passed to Scan, Aggregate, Do, DistinctUntilChanged(comparer), and DistinctUntilChangedBy threw exceptions back to the upstream producer instead of forwarding OnError to the downstream observer and disposing the subscription. Downstream observer exceptions still propagate to the producer after upstream disposal.

Closes #241

In CI run 44742883594, DebounceUntil(...).Take(1).FirstAsync() hung until the 15-minute runner timeout. When a downstream async witness hopped threads while cancelling its disposal token source and disposed its upstream subscription from inside an active notification, MarkDisposingFromNotification did not propagate to upstream witnesses or stop coordinators. The upstream witness saw an active call owned by the original thread and waited forever on its own in-flight notification.

Breaking changes

None

How this was verified

Added unit tests covering callback faults, fatal exception passthrough, downstream observer exception propagation, and cross-thread chained async witness and coordinator teardown, verified 100% line and branch coverage across all touched files, and ran nuget-cleanup, nuget-outdated, and detect-duplicates across src/.

Notes for the reviewer

  • Start with WitnessAsync.cs, WitnessAsyncState.cs, DisposableAsyncSlot.cs, and AsyncStopCoordinator{T,TOther}.cs for the async notification-disposal propagation fix. Both DisposeFromNotificationAsync and terminal OnCompletedAsync teardown propagate notification context to upstream IWitnessState subscriptions so chained operators never wait on their own caller.
  • UnaryWitnessDelivery.cs and DirectSequenceEmission.cs hold the shared synchronous delivery and sequence fast-path guards. The updates to FoldWitness, ReduceWitness, TapWitness, TapSignal, UniqueWitness, UniqueSignal, UniqueByWitness, and UniqueBySignal wire those operators into the shared helpers and are mechanical to review.
  • TapWitness forwarding members carry [MethodImpl(MethodImplOptions.AggressiveInlining)] in the ReactiveUI.Primitives.Core public API baselines.
  • Microsoft.Extensions.TimeProvider.Testing is banded inside <Choose> (11.0.0 on net11.0, 10.11.1 on net10.0), and ObservableEvents preserves its explicit Microsoft.CodeAnalysis.CSharp 4.8.0 generator baseline.

Checklist

  • I have read the Contribute guide
  • The PR title follows Conventional Commits
  • Tests cover this change, or the summary says why they do not
  • New or changed public API has XML documentation

- Route non-fatal user callback exceptions in Scan, Aggregate, Do, DistinctUntilChanged, and DistinctUntilChangedBy to OnError.
- Mark faulted operators stopped and dispose their upstream subscriptions on live and synchronous sequence paths.
- Propagate notification-context disposal across chained async witnesses and stop coordinators. Cross-thread teardown inside an active notification deadlocks without this flag.
- Rewrite the DebounceUntil immediate-emission test to verify immediate delivery with ManualTimeProvider.
- Remove unused and transitive NuGet package entries and update dependencies to current releases.

Closes #241
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.98%. Comparing base (246a924) to head (9db56a4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #248   +/-   ##
=======================================
  Coverage   99.98%   99.98%           
=======================================
  Files        1012     1012           
  Lines       27139    27207   +68     
  Branches     3259     3279   +20     
=======================================
+ Hits        27135    27203   +68     
  Misses          4        4           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

Copy link
Copy Markdown

@glennawatson
glennawatson merged commit f37a13c into main Nov 20, 2026
16 checks passed
@glennawatson
glennawatson deleted the fix/callback-exceptions-and-async-teardown branch November 20, 2026 15:27
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.

Scan, Aggregate, Do and DistinctUntilChanged throw callback exceptions to the producer instead of delivering OnError

1 participant