reactor/reactor-core
在 GitHub 查看EmitterProcessor queue not cleared on immediate cancellation
Open
#3,359 创建于 2023年2月20日
area/doOnDiscardhelp wantedtype/bug
仓库指标
- Star
- (4,748 star)
- PR 合并指标
- (平均合并 16天 15小时) (30 天内合并 25 个 PR)
描述
EmitterProcessor#remove has support to discard the buffer once the last subscriber is gone. However, it returns early if the subscribers array is already EMPTY. For cases where the subscription is immediately cancelled (e.g. .take(0)) this may leak the buffered elements.
Here is a repro case:
@Test
void shouldClearBufferOnCancellation() {
BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
Many<Integer> sink = Sinks.many().unicast().onBackpressureBuffer(queue);
sink.tryEmitNext(1);
sink.tryEmitNext(2);
sink.tryEmitNext(3);
assertThat(queue).hasSize(3);
sink.asFlux().take(0).blockLast();
assertThat(queue).isEmpty();
}
As a workaround .takeWhile(x -> false) does make the test pass for example.