diff --git a/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/http/LivenessWebSocket.kt b/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/http/LivenessWebSocket.kt index c69a2aa6c1..0d36d9e8a0 100644 --- a/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/http/LivenessWebSocket.kt +++ b/aws-predictions/src/main/java/com/amplifyframework/predictions/aws/http/LivenessWebSocket.kt @@ -413,7 +413,8 @@ internal class LivenessWebSocket( } fun destroy() { - webSocket?.cancel() + // Close gracefully; 1000 means "normal closure" + webSocket?.close(1000, null) } companion object { diff --git a/aws-predictions/src/test/java/com/amplifyframework/predictions/aws/http/LivenessWebSocketTest.kt b/aws-predictions/src/test/java/com/amplifyframework/predictions/aws/http/LivenessWebSocketTest.kt index c893214560..85c4cc841a 100644 --- a/aws-predictions/src/test/java/com/amplifyframework/predictions/aws/http/LivenessWebSocketTest.kt +++ b/aws-predictions/src/test/java/com/amplifyframework/predictions/aws/http/LivenessWebSocketTest.kt @@ -258,7 +258,7 @@ internal class LivenessWebSocketTest { } @Test - fun `web socket error cancels websocket`() { + fun `web socket error closes websocket`() { livenessWebSocket.webSocket = mockk() val event = ValidationException("ValidationException") val headers = mapOf( @@ -272,7 +272,7 @@ internal class LivenessWebSocketTest { livenessWebSocket.webSocketListener.onMessage(mockk(), encodedByteString) - verify { livenessWebSocket.webSocket!!.cancel() } + verify { livenessWebSocket.webSocket!!.close(1000, any()) } } @Test