Skip to content

Commit

Permalink
Fix Zip(IEnumerable) NullReferenceException if a source completes imm…
Browse files Browse the repository at this point in the history
…ediately

(cherry picked from commit 1b19cb6)
  • Loading branch information
akarnokd authored and danielcweber committed Oct 1, 2018
1 parent 1888ca8 commit 1990de7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Rx.NET/Source/src/System.Reactive/Linq/Observable/Zip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IDisposable>())
{
Disposable.TryDispose(ref subscriptions[index]);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4448,6 +4448,41 @@ public void Zip_AtLeastOneThrows4()

#endregion

[Fact]
public void Zip2WithImmediateReturn()
{
Observable.Zip<Unit, Unit, Unit>(
Observable.Return(Unit.Default),
Observable.Return(Unit.Default),
(_, __) => Unit.Default
)
.Subscribe(_ => { });
}

[Fact]
public void Zip3WithImmediateReturn()
{
Observable.Zip<Unit, Unit, Unit, Unit>(
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
}

0 comments on commit 1990de7

Please sign in to comment.