diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnection.java b/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnection.java index 08ec485ea..6cf3d56eb 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnection.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnection.java @@ -388,7 +388,7 @@ public class WebSocketConnection implements MessageAvailabilityListener, Disconn Mono.fromFuture(() -> sendMessage(envelope)).timeout(sendFuturesTimeout) // Note that this will retry both for "send to client" timeouts and failures to delete messages on // acknowledgement - .retryWhen(Retry.backoff(4, Duration.ofSeconds(1))), + .retryWhen(Retry.backoff(4, Duration.ofSeconds(1)).filter(throwable -> !isConnectionClosedException(throwable))), MESSAGE_SENDER_MAX_CONCURRENCY) .doOnError(this::measureSendMessageErrors) .subscribeOn(messageDeliveryScheduler) @@ -410,10 +410,7 @@ public class WebSocketConnection implements MessageAvailabilityListener, Disconn if (e instanceof TimeoutException) { errorType = "timeout"; - } else if (e instanceof java.nio.channels.ClosedChannelException || - e == WebSocketResourceProvider.CONNECTION_CLOSED_EXCEPTION || - e instanceof org.eclipse.jetty.io.EofException || - (e instanceof StaticException staticException && "Closed".equals(staticException.getMessage()))) { + } else if (isConnectionClosedException(e)) { errorType = "connectionClosed"; } else { logger.warn("Send message failed", e); @@ -427,6 +424,13 @@ public class WebSocketConnection implements MessageAvailabilityListener, Disconn .increment(); } + private static boolean isConnectionClosedException(final Throwable throwable) { + return throwable instanceof java.nio.channels.ClosedChannelException || + throwable == WebSocketResourceProvider.CONNECTION_CLOSED_EXCEPTION || + throwable instanceof org.eclipse.jetty.io.EofException || + (throwable instanceof StaticException staticException && "Closed".equals(staticException.getMessage())); + } + private CompletableFuture sendMessage(Envelope envelope) { final UUID messageGuid = UUID.fromString(envelope.getServerGuid());