@@ -56,6 +56,8 @@ public final class UnboundedProcessor<T> extends FluxProcessor<T, T>
56
56
57
57
volatile boolean cancelled ;
58
58
59
+ volatile boolean terminated ;
60
+
59
61
volatile int once ;
60
62
61
63
@ SuppressWarnings ("rawtypes" )
@@ -163,6 +165,9 @@ void drainFused(Subscriber<? super T> a) {
163
165
for (; ; ) {
164
166
165
167
if (cancelled ) {
168
+ if (terminated ) {
169
+ this .clear ();
170
+ }
166
171
hasDownstream = false ;
167
172
return ;
168
173
}
@@ -192,7 +197,7 @@ void drainFused(Subscriber<? super T> a) {
192
197
193
198
public void drain () {
194
199
if (WIP .getAndIncrement (this ) != 0 ) {
195
- if (cancelled ) {
200
+ if ((! outputFused && cancelled ) || terminated ) {
196
201
this .clear ();
197
202
}
198
203
return ;
@@ -353,7 +358,7 @@ public void cancel() {
353
358
cancelled = true ;
354
359
355
360
if (WIP .getAndIncrement (this ) == 0 ) {
356
- if (!outputFused ) {
361
+ if (!outputFused || terminated ) {
357
362
this .clear ();
358
363
}
359
364
hasDownstream = false ;
@@ -382,24 +387,20 @@ public boolean isEmpty() {
382
387
383
388
@ Override
384
389
public void clear () {
390
+ terminated = true ;
385
391
if (DISCARD_GUARD .getAndIncrement (this ) != 0 ) {
386
392
return ;
387
393
}
388
394
389
395
int missed = 1 ;
390
396
391
397
for (; ; ) {
392
- while (!queue .isEmpty ()) {
393
- T t = queue .poll ();
394
- if (t != null ) {
395
- release (t );
396
- }
398
+ T t ;
399
+ while ((t = queue .poll ()) != null ) {
400
+ release (t );
397
401
}
398
- while (!priorityQueue .isEmpty ()) {
399
- T t = priorityQueue .poll ();
400
- if (t != null ) {
401
- release (t );
402
- }
402
+ while ((t = priorityQueue .poll ()) != null ) {
403
+ release (t );
403
404
}
404
405
405
406
missed = DISCARD_GUARD .addAndGet (this , -missed );
@@ -434,16 +435,14 @@ public void dispose() {
434
435
for (; ; ) {
435
436
final CoreSubscriber <? super T > a = this .actual ;
436
437
437
- if (!outputFused ) {
438
+ if (!outputFused || terminated ) {
438
439
clear ();
439
440
}
440
441
441
442
if (a != null && once ) {
442
443
try {
443
- System .out .println ("sending error" );
444
444
a .onError (error );
445
445
} catch (Throwable ignored ) {
446
- System .out .println ("bubbled" );
447
446
ignored .printStackTrace ();
448
447
}
449
448
}
0 commit comments