From 14acc3b9fe0e4c9490fe48680be19ee329303a1a Mon Sep 17 00:00:00 2001 From: Tyler Roach Date: Mon, 19 Feb 2024 12:29:30 -0500 Subject: [PATCH] datastore(fix): Fixes previous PR which was inadvertently creating multiple websockets. (#2719) --- .../api/aws/SubscriptionEndpoint.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/aws-api/src/main/java/com/amplifyframework/api/aws/SubscriptionEndpoint.java b/aws-api/src/main/java/com/amplifyframework/api/aws/SubscriptionEndpoint.java index 3656db80d..d80d75148 100644 --- a/aws-api/src/main/java/com/amplifyframework/api/aws/SubscriptionEndpoint.java +++ b/aws-api/src/main/java/com/amplifyframework/api/aws/SubscriptionEndpoint.java @@ -141,17 +141,17 @@ void requestSubscription( pendingSubscriptionIds.add(subscriptionId); socketListener = webSocketListener; socket = webSocket; - } - // Every request waits here for the connection to be ready. - Connection connection = socketListener.waitForConnectionReady(); - if (connection.hasFailure()) { - // If the latch didn't count all the way down - if (pendingSubscriptionIds.remove(subscriptionId)) { - // The subscription was pending, so we need to emit an error. - onSubscriptionError.accept( - new ApiException(connection.getFailureReason(), AmplifyException.TODO_RECOVERY_SUGGESTION)); - return; + // Every request waits here for the connection to be ready. + Connection connection = socketListener.waitForConnectionReady(); + if (connection.hasFailure()) { + // If the latch didn't count all the way down + if (pendingSubscriptionIds.remove(subscriptionId)) { + // The subscription was pending, so we need to emit an error. + onSubscriptionError.accept( + new ApiException(connection.getFailureReason(), AmplifyException.TODO_RECOVERY_SUGGESTION)); + return; + } } } @@ -257,7 +257,7 @@ private void notifySubscriptionData(String subscriptionId, String data) throws A dispatcher.dispatchNextMessage(data); } - synchronized void releaseSubscription(String subscriptionId) throws ApiException { + void releaseSubscription(String subscriptionId) throws ApiException { // First thing we should do is remove it from the pending subscription collection so // the other methods can't grab a hold of the subscription. final Subscription subscription = subscriptions.get(subscriptionId);