Skip to content

Commit c40e359

Browse files
committed
fixes GroupBy overflow issue
Signed-off-by: Oleh Dokuka <[email protected]>
1 parent 868dca9 commit c40e359

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

reactor-core/src/main/java/reactor/core/publisher/FluxGroupBy.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ public K key() {
515515
volatile boolean outputFused;
516516

517517
int produced;
518+
boolean isFirstRequest = true;
518519

519520
UnicastGroupedFlux(K key,
520521
Queue<V> queue,
@@ -572,7 +573,16 @@ void drainRegular(Subscriber<? super V> a) {
572573
if (e != 0) {
573574
GroupByMain<?, K, V> main = parent;
574575
if (main != null) {
575-
main.s.request(e);
576+
if (this.isFirstRequest) {
577+
this.isFirstRequest = false;
578+
long toRequest = e - 1;
579+
580+
if (toRequest > 0) {
581+
main.s.request(toRequest);
582+
}
583+
} else {
584+
main.s.request(e);
585+
}
576586
}
577587
if (r != Long.MAX_VALUE) {
578588
REQUESTED.addAndGet(this, -e);
@@ -751,7 +761,16 @@ void tryReplenish() {
751761
produced = 0;
752762
GroupByMain<?, K, V> main = parent;
753763
if (main != null) {
754-
main.s.request(p);
764+
if (this.isFirstRequest) {
765+
this.isFirstRequest = false;
766+
p--;
767+
768+
if (p > 0) {
769+
main.s.request(p);
770+
}
771+
} else {
772+
main.s.request(p);
773+
}
755774
}
756775
}
757776
}

0 commit comments

Comments
 (0)