Skip to content

Commit 665b10e

Browse files
gregwscrat98
authored andcommitted
Issue jetty#11803 - updates from review
1 parent 5a38816 commit 665b10e

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

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

+20-17
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ private void onSubscribe(Flow.Subscriber<? super Content.Chunk> subscriber, Cont
8181
{
8282
// As per rule 2.13, we MUST consider subscription cancelled and
8383
// MUST raise this error condition in a fashion that is adequate for the runtime environment.
84-
subscription.cancel(new Suppressed(err));
85-
LOG.error("Flow.Subscriber " + subscriber + " violated rule 2.13", err);
84+
subscription.cancel(new SuppressedException(err));
85+
if (LOG.isTraceEnabled())
86+
LOG.trace("Flow.Subscriber " + subscriber + " violated rule 2.13", err);
8687
}
8788
}
8889

@@ -106,7 +107,8 @@ private void onMultiSubscribe(Flow.Subscriber<? super Content.Chunk> subscriber)
106107
{
107108
// As per rule 2.13, we MUST consider subscription cancelled and
108109
// MUST raise this error condition in a fashion that is adequate for the runtime environment.
109-
LOG.error("Flow.Subscriber " + subscriber + " violated rule 2.13", err);
110+
if (LOG.isTraceEnabled())
111+
LOG.trace("Flow.Subscriber " + subscriber + " violated rule 2.13", err);
110112
}
111113
}
112114

@@ -168,12 +170,13 @@ protected Action process()
168170
{
169171
if (cancelled == COMPLETED)
170172
this.subscriber.onComplete();
171-
else if (!(cancelled instanceof Suppressed))
173+
else if (!(cancelled instanceof SuppressedException))
172174
this.subscriber.onError(cancelled);
173175
}
174176
catch (Throwable err)
175177
{
176-
LOG.error("Flow.Subscriber " + subscriber + " violated rule 2.13", err);
178+
if (LOG.isTraceEnabled())
179+
LOG.trace("Flow.Subscriber " + subscriber + " violated rule 2.13", err);
177180
}
178181
this.subscriber = null;
179182
return Action.SUCCEEDED;
@@ -183,8 +186,8 @@ else if (!(cancelled instanceof Suppressed))
183186

184187
if (chunk == null)
185188
{
186-
content.demand(this::iterate);
187-
return Action.IDLE;
189+
content.demand(this::succeeded);
190+
return Action.SCHEDULED;
188191
}
189192

190193
if (Content.Chunk.isFailure(chunk))
@@ -201,8 +204,9 @@ else if (!(cancelled instanceof Suppressed))
201204
catch (Throwable err)
202205
{
203206
chunk.release();
204-
cancel(new Suppressed(err));
205-
LOG.error("Flow.Subscriber " + subscriber + " violated rule 2.13", err);
207+
cancel(new SuppressedException(err));
208+
if (LOG.isTraceEnabled())
209+
LOG.trace("Flow.Subscriber " + subscriber + " violated rule 2.13", err);
206210
return Action.IDLE;
207211
}
208212
chunk.release();
@@ -243,7 +247,7 @@ public void request(long n)
243247
@Override
244248
public void cancel()
245249
{
246-
cancel(new Suppressed("Subscription was cancelled manually"));
250+
cancel(new SuppressedException("Subscription was cancelled manually"));
247251
}
248252

249253
public void cancel(Throwable cause)
@@ -252,9 +256,8 @@ public void cancel(Throwable cause)
252256
//
253257
// As per rule 3.5, this handles cancellation requests, and is idempotent, thread-safe and not
254258
// synchronously performing heavy computations
255-
if (!cancelled.compareAndSet(null, cause))
256-
return;
257-
this.iterate();
259+
if (cancelled.compareAndSet(null, cause))
260+
this.iterate();
258261
}
259262

260263
// Publisher notes
@@ -280,7 +283,7 @@ public void cancel(Throwable cause)
280283

281284
// Subscription notes
282285
//
283-
// Subscription.cancel -> cancel(new Suppressed("Subscription was cancelled manually"))
286+
// Subscription.cancel -> cancel(new SuppressedException("Subscription was cancelled manually"))
284287
// It's not clearly specified in the specification, but according to:
285288
// - the issue: https://github.com/reactive-streams/reactive-streams-jvm/issues/458
286289
// - TCK test 'untested_spec108_possiblyCanceledSubscriptionShouldNotReceiveOnErrorOrOnCompleteSignals'
@@ -291,14 +294,14 @@ public void cancel(Throwable cause)
291294
// java.lang.IllegalArgumentException if the argument is <= 0.
292295
}
293296

294-
private static class Suppressed extends Throwable
297+
private static class SuppressedException extends Exception
295298
{
296-
Suppressed(String message)
299+
SuppressedException(String message)
297300
{
298301
super(message);
299302
}
300303

301-
Suppressed(Throwable cause)
304+
SuppressedException(Throwable cause)
302305
{
303306
super(cause.getMessage(), cause);
304307
}

0 commit comments

Comments
 (0)