diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs index b78960cf3e..50b8a94257 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs @@ -661,7 +661,11 @@ private void OnCompleted(int index) } else { - _subscriptions[index].Dispose(); + var subscriptions = Volatile.Read(ref _subscriptions); + if (subscriptions != null && subscriptions != Array.Empty()) + { + Disposable.TryDispose(ref subscriptions[index]); + } } } } diff --git a/Rx.NET/Source/tests/Tests.System.Reactive/Tests/Linq/Observable/ZipTest.cs b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/Linq/Observable/ZipTest.cs index 4a0cd1eed6..48cec2be4a 100644 --- a/Rx.NET/Source/tests/Tests.System.Reactive/Tests/Linq/Observable/ZipTest.cs +++ b/Rx.NET/Source/tests/Tests.System.Reactive/Tests/Linq/Observable/ZipTest.cs @@ -4448,6 +4448,41 @@ public void Zip_AtLeastOneThrows4() #endregion + [Fact] + public void Zip2WithImmediateReturn() + { + Observable.Zip( + Observable.Return(Unit.Default), + Observable.Return(Unit.Default), + (_, __) => Unit.Default + ) + .Subscribe(_ => { }); + } + + [Fact] + public void Zip3WithImmediateReturn() + { + Observable.Zip( + Observable.Return(Unit.Default), + Observable.Return(Unit.Default), + Observable.Return(Unit.Default), + (_, __, ___) => Unit.Default + ) + .Subscribe(_ => { }); + } + + [Fact] + public void ZipEnumerableWithImmediateReturn() + { + Enumerable.Range(0, 100) + .Select(_ => Observable.Return(Unit.Default)) + .Zip() + .Subscribe(_ => + { + + } + ); + } } #pragma warning restore IDE0039 // Use local function }