From 1b36cf53851f05fad3c91b172b91fedda17af31f Mon Sep 17 00:00:00 2001 From: zb-sr <155634845+zb-sr@users.noreply.github.com> Date: Mon, 1 Jul 2024 11:55:38 +0200 Subject: [PATCH] Fix reconnect issues --- .../sdk/internal/connection/WebSocketConnection.java | 2 +- .../mbs/sdk/internal/protocol/ProtocolEngine.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sdk/src/main/java/com/sportradar/mbs/sdk/internal/connection/WebSocketConnection.java b/src/sdk/src/main/java/com/sportradar/mbs/sdk/internal/connection/WebSocketConnection.java index fe813599..3d78578c 100644 --- a/src/sdk/src/main/java/com/sportradar/mbs/sdk/internal/connection/WebSocketConnection.java +++ b/src/sdk/src/main/java/com/sportradar/mbs/sdk/internal/connection/WebSocketConnection.java @@ -88,7 +88,7 @@ private void sendLoop() { try { sendMsg(ws, msgs); } catch (final Exception e) { - this.receiveQueue.add(new ExcWsOutputMessage(msg, new WebSocketConnectionException(e))); + this.receiveQueue.add(new ExcWsOutputMessage(null, new WebSocketConnectionException(e))); reconnectWebSocket(ws, false); sendMsg(this.webSocket.get(), msgs); } diff --git a/src/sdk/src/main/java/com/sportradar/mbs/sdk/internal/protocol/ProtocolEngine.java b/src/sdk/src/main/java/com/sportradar/mbs/sdk/internal/protocol/ProtocolEngine.java index a3756181..09434496 100644 --- a/src/sdk/src/main/java/com/sportradar/mbs/sdk/internal/protocol/ProtocolEngine.java +++ b/src/sdk/src/main/java/com/sportradar/mbs/sdk/internal/protocol/ProtocolEngine.java @@ -124,6 +124,10 @@ private void enqueueSendMsg(final Awaiter awaiter releaseAwaiter(awaiter.getCorrelationId()); return; } + if (awaiter.getFuture().isDone()) { + releaseAwaiter(awaiter.getCorrelationId()); + return; + } sendQueue.add(awaiter.getSendWsInputMessage()); @@ -253,6 +257,9 @@ private void handleExcWsOutputMessage(final ExcWsOutputMessage msg) { } private boolean responseReceived(final String correlationId, final Response response) { + if (correlationId == null) { + return false; + } final Awaiter awaiter = correlationIdAwaiter.get(correlationId); if (response.getContent() != null && awaiter != null @@ -265,6 +272,9 @@ private boolean responseReceived(final String correlationId, final Response resp } private boolean responseReceived(final String correlationId, final SdkException sdkException) { + if (correlationId == null) { + return false; + } final Awaiter awaiter = correlationIdAwaiter.get(correlationId); if (awaiter != null) { awaiter.completeWithException(sdkException);