Skip to content

Commit 679cea6

Browse files
committed
Log and retry exceptions during the initial websocket connection instead of silently discarding them
1 parent ccce7b6 commit 679cea6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 2.4.1
2+
## Fixes
3+
- Log and retry exceptions during the initial websocket connection instead of silently discarding them
4+
5+
---
6+
17
# 2.4.0
28
## New Features
39
- Allow proxying the new server management protocol added in 1.21.9 through the Exaroton API

src/main/java/com/exaroton/api/ws/WebSocketConnection.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ private void connect() {
234234
.thenAccept(ws -> {
235235
this.logger.debug("Connected to {}", uri);
236236
this.client = ws;
237+
})
238+
.exceptionally(t -> {
239+
logger.error("Websocket connection failed", t);
240+
scheduleReconnect();
241+
return null;
237242
});
238243
}
239244

@@ -372,6 +377,15 @@ public CompletionStage<?> onClose(WebSocket webSocket, int statusCode, String re
372377
}
373378
}
374379

380+
this.scheduleReconnect();
381+
return null;
382+
}
383+
384+
/**
385+
* This method is called when the connection is closed. It automatically starts a reconnect timer
386+
* if autoReconnect is enabled.
387+
*/
388+
private void scheduleReconnect() {
375389
if (this.shouldAutoReconnect()) {
376390
reconnectTimer = new Timer();
377391
logger.debug("Reconnecting in 5s");
@@ -382,7 +396,6 @@ public void run() {
382396
}
383397
}, 5000, 5000);
384398
}
385-
return null;
386399
}
387400

388401
@Override

0 commit comments

Comments
 (0)