[rest] Suppress ISE in 'SseBroadcaster' if sink already has been closed (#1540)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
pull/1541/head
Christoph Weitkamp 2020-07-09 23:16:01 +02:00 committed by GitHub
parent 6c935985a6
commit a142e6746e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 8 deletions

View File

@ -93,6 +93,11 @@ public class SseBroadcaster<@NonNull I> implements Closeable {
public void sendIf(final OutboundSseEvent event, Predicate<I> predicate) {
logger.trace("broadcast to potential {} sinks", sinks.size());
sinks.forEach((sink, info) -> {
// Check if we should send at all.
if (!predicate.test(info)) {
return;
}
if (sink.isClosed()) {
// We are using a concurrent collection, so we are allowed to modify the collection asynchronous (we
// don't know if there is currently an iteration in progress or not, but it does not matter).
@ -100,11 +105,6 @@ public class SseBroadcaster<@NonNull I> implements Closeable {
return;
}
// Check if we should send at all.
if (!predicate.test(info)) {
return;
}
sink.send(event).exceptionally(th -> {
close(sink);
@ -118,10 +118,11 @@ public class SseBroadcaster<@NonNull I> implements Closeable {
if (thClass.equals("class org.eclipse.jetty.io.EofException")) {
// The peer terminates the connection.
} else if (th instanceof IllegalStateException && message != null
&& (message.equals("The sink is already closed, unable to queue SSE event for send")
&& (message.equals("The sink is already closed, unable to queue SSE event for send") //
|| message.equals("The sink has been already closed") //
|| message.equals("AsyncContext completed and/or Request lifecycle recycled"))) {
// java.lang.IllegalStateException: The sink is already closed, unable to queue SSE event for
// send
// java.lang.IllegalStateException: The sink is already closed, unable to queue SSE event for send
// java.lang.IllegalStateException: The sink has been already closed
// java.lang.IllegalStateException: AsyncContext completed and/or Request lifecycle recycled
} else {
logger.warn("failure", th);