Skip to content

Commit

Permalink
add reconnecting behaviour when an unintentional disconnect occures (…
Browse files Browse the repository at this point in the history
…this can happen when the gateway or nginx container get killed);

Signed-off-by: Stefan Maute <stefan.maute@bosch.io>
  • Loading branch information
Stefan Maute committed Jun 8, 2021
1 parent 644aecd commit 3062cf0
Showing 1 changed file with 11 additions and 1 deletion.
Expand Up @@ -86,6 +86,7 @@ public final class WebSocketMessagingProvider extends WebSocketAdapter implement
private final Map<Object, String> subscriptionMessages;
private final AtomicBoolean reconnecting = new AtomicBoolean(false);
private final AtomicBoolean initializing = new AtomicBoolean(false);
private final AtomicBoolean websocketClosed = new AtomicBoolean(false);
private final CompletableFuture<WebSocket> initializationFuture = new CompletableFuture<>();

private final AtomicReference<WebSocket> webSocket;
Expand Down Expand Up @@ -270,6 +271,7 @@ public void close() {
connectExecutor.shutdownNow();
authenticationProvider.destroy();
adaptableBus.shutdownExecutor();
websocketClosed.getAndSet(true);
final WebSocket ws = webSocket.get();
if (ws != null) {
ws.disconnect();
Expand Down Expand Up @@ -310,7 +312,15 @@ public void onDisconnected(final WebSocket websocket, final WebSocketFrame serve
serverCloseFrame.getCloseCode(),
serverCloseFrame.getCloseReason());
handleReconnectionIfEnabled();
} else {
} else if (!websocketClosed.get()) {
// client closed connection because of a connection interruption or something similar
LOGGER.info("Client <{}>: WebSocket connection to endpoint <{}> was unintentionally closed by client " +
"- client will try to reconnect if enabled!",
sessionId, messagingConfiguration.getEndpointUri());
handleReconnectionIfEnabled();
}
else {
// only when close() was called we should end here
LOGGER.info("Client <{}>: WebSocket connection to endpoint <{}> was closed by client",
sessionId, messagingConfiguration.getEndpointUri());
}
Expand Down

0 comments on commit 3062cf0

Please sign in to comment.