Skip to content

Commit 524988c

Browse files
committed
Issue jetty#11803 - refactoring
1 parent 5a54e00 commit 524988c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/content/ContentSourcePublisher.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import java.util.Objects;
1717
import java.util.concurrent.CancellationException;
18-
import java.util.concurrent.CompletionException;
1918
import java.util.concurrent.Flow;
2019
import java.util.concurrent.atomic.AtomicLong;
2120
import java.util.concurrent.atomic.AtomicReference;
@@ -92,11 +91,9 @@ private void onMultiSubscribe(Flow.Subscriber<? super Content.Chunk> subscriber)
9291
// As per rule 1.9, we need to throw a `java.lang.NullPointerException`
9392
// if the `Subscriber` is `null`
9493
if (subscriber == null)
95-
{
9694
throw new NullPointerException("Flow.Subscriber must not be null");
97-
}
98-
LastWillSubscription subscription = new ExhaustedSubscription();
9995

96+
LastWillSubscription subscription = new ExhaustedSubscription();
10097
// As per 1.9, this method must return normally (i.e. not throw).
10198
try
10299
{
@@ -196,7 +193,7 @@ public void cancel(LastWill lastWill)
196193
private static final class ActiveSubscription extends IteratingCallback implements LastWillSubscription
197194
{
198195
private static final long NO_MORE_DEMAND = -1;
199-
private static final Throwable COMPLETED = new StaticException("Source.Content read fully");
196+
private static final LastWill COMPLETED = new LastWill(new StaticException("Source.Content read fully"), FinalSignal.COMPLETE);
200197
private final AtomicReference<LastWill> cancelled;
201198
private final AtomicLong demand;
202199
private Content.Source content;
@@ -230,6 +227,7 @@ protected Action process()
230227
// drop any references to the corresponding subscriber.
231228
this.demand.set(NO_MORE_DEMAND);
232229
// TODO: HttpChannelState does not satisfy the contract of Content.Source "If read() has returned a last chunk, this is a no operation."
230+
// https://github.com/jetty/jetty.project/issues/11879
233231
if (finalSignal != FinalSignal.COMPLETE)
234232
this.content.fail(reason);
235233
this.content = null;
@@ -270,14 +268,16 @@ protected Action process()
270268
}
271269
catch (Throwable err)
272270
{
271+
chunk.release();
273272
cancel(err, FinalSignal.SUPPRESS);
274273
LOG.error("Flow.Subscriber " + subscriber + " violated rule 2.13", err);
274+
return Action.IDLE;
275275
}
276276
chunk.release();
277277

278278
if (chunk.isLast())
279279
{
280-
cancel(COMPLETED, FinalSignal.COMPLETE);
280+
cancel(COMPLETED);
281281
return Action.IDLE;
282282
}
283283

0 commit comments

Comments
 (0)