Race condition in reduce with seed cancellation can lead to NPE #1393
Closed
Description
Expected behavior
A reducing Flux
with a seed value can safely be cancelled.
Actual behavior
The BiFunction
can be fed a null
value in case there is a concurrent cancel()
along the first onNext(T)
. This is due to cancel
nulling out the internal accumulated value
and onNext
not checking for nulls.
Steps to reproduce
@Test
public void onNextAndCancelRace() {
List<Integer> list = new ArrayList<>();
final AssertSubscriber<Object> testSubscriber = AssertSubscriber.create();
MonoReduceSeed.ReduceSeedSubscriber<Integer, List<Integer>> sub =
new MonoReduceSeed.ReduceSeedSubscriber<>(testSubscriber,
(l, next) -> {
l.add(next);
return l;
}, list);
sub.onSubscribe(Operators.emptySubscription());
sub.cancel();
sub.onNext(1);
testSubscriber.assertNoError(); //=> fails, NullPointerException in lambda above
}
Reactor Core version
3.1.10.RELEASE