Skip to content

Commit

Permalink
Fix "initialConnectRetryEnabled" config suppressing "reconnectEnabled".
Browse files Browse the repository at this point in the history
Signed-off-by: Yufei Cai <[email protected]>
(cherry picked from commit 42b12e0)
  • Loading branch information
yufei-cai authored and jokraehe committed Dec 22, 2020
1 parent 55d5ca2 commit ece2426
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public CompletionStage<?> initializeAsync() {
// this method may be called multiple times.
if (!initializing.getAndSet(true)) {
if (webSocket.get() == null) {
return connectWithPotentialRetries(this::createWebsocket, initializationFuture)
return connectWithPotentialRetries(this::createWebsocket, initializationFuture,
messagingConfiguration.isInitialConnectRetryEnabled())
.thenApply(ws -> {
setWebSocket(ws);
return this;
Expand Down Expand Up @@ -335,12 +336,12 @@ public void onError(final WebSocket websocket, final WebSocketException cause) {
}

private CompletableFuture<WebSocket> connectWithPotentialRetries(final Supplier<WebSocket> webSocket,
final CompletableFuture<WebSocket> future) {
final CompletableFuture<WebSocket> future,
final boolean retry) {

try {
final Predicate<Throwable> isRecoverable = messagingConfiguration.isInitialConnectRetryEnabled()
? WebSocketMessagingProvider::isRecoverable
: exception -> false;
final Predicate<Throwable> isRecoverable =
retry ? WebSocketMessagingProvider::isRecoverable : exception -> false;
return Retry.retryTo("initialize WebSocket connection",
() -> initiateConnection(webSocket.get()))
.inClientSession(sessionId)
Expand Down Expand Up @@ -372,7 +373,8 @@ private void handleReconnectionIfEnabled() {
}

private void reconnectWithRetries() {
this.connectWithPotentialRetries(this::recreateWebSocket, new CompletableFuture<>())
this.connectWithPotentialRetries(this::recreateWebSocket, new CompletableFuture<>(),
messagingConfiguration.isReconnectEnabled())
.thenAccept(reconnectedWebSocket -> {
setWebSocket(reconnectedWebSocket);
reconnecting.set(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void connectToUnknownHostWithErrorConsumer() throws Exception {
expectNoMsg(errors);
}

@Ignore
@Ignore("TODO: fix it")
@Test(timeout = 10_000)
public void serviceUnavailable() throws Exception {
final int numberOfRecoverableErrors = 3;
Expand Down

0 comments on commit ece2426

Please sign in to comment.