Don't retry "connection closed" errors

This commit is contained in:
Jon Chambers
2025-07-31 15:38:42 -04:00
committed by Jon Chambers
parent 5cb3a053fb
commit a4804f6501

View File

@@ -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<Void> sendMessage(Envelope envelope) {
final UUID messageGuid = UUID.fromString(envelope.getServerGuid());