From b0810c52bee3e15518eaf918f25aaab56cc05f61 Mon Sep 17 00:00:00 2001 From: Manohar Peswani Date: Wed, 25 Apr 2018 17:32:58 +0530 Subject: [PATCH] 1. crash fix where socket send message when connection is not there 2. retry of websocket was blocked by a condition in Connection.java 3. crash fix where sometimes event comes null and gives null pointor exception in DeepstreamClientAbstract.java --- src/main/java/io/deepstream/Connection.java | 2 +- .../java/io/deepstream/DeepstreamClientAbstract.java | 12 +++++++----- .../java/io/deepstream/JavaEndpointWebsocket.java | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/deepstream/Connection.java b/src/main/java/io/deepstream/Connection.java index 15acc07..577429d 100644 --- a/src/main/java/io/deepstream/Connection.java +++ b/src/main/java/io/deepstream/Connection.java @@ -398,7 +398,7 @@ private void tryReconnect() { int maxReconnectInterval = options.getMaxReconnectInterval(); if( this.reconnectionAttempt < maxReconnectAttempts ) { - if(this.globalConnectivityState == GlobalConnectivityState.CONNECTED) { + if(this.globalConnectivityState == GlobalConnectivityState.DISCONNECTED) { this.setState(ConnectionState.RECONNECTING); this.reconnectTimeout = new Timer(); this.reconnectTimeout.schedule(new TimerTask() { diff --git a/src/main/java/io/deepstream/DeepstreamClientAbstract.java b/src/main/java/io/deepstream/DeepstreamClientAbstract.java index e1fd622..5bca2cb 100644 --- a/src/main/java/io/deepstream/DeepstreamClientAbstract.java +++ b/src/main/java/io/deepstream/DeepstreamClientAbstract.java @@ -45,11 +45,13 @@ void onError(Topic topic, Event event, String msg) throws DeepstreamException { * Help to diagnose the problem quicker by checking for * some mon problems */ - if( event.equals( Event.ACK_TIMEOUT ) || event.equals( Event.RESPONSE_TIMEOUT ) ) { - if( getConnectionState().equals( ConnectionState.AWAITING_AUTHENTICATION ) ) { - String errMsg = "Your message timed out because you\'re not authenticated. Have you called login()?"; - onError( Topic.ERROR, Event.NOT_AUTHENTICATED, errMsg ); - return; + if (event != null) { + if( event.equals( Event.ACK_TIMEOUT ) || event.equals( Event.RESPONSE_TIMEOUT ) ) { + if( getConnectionState().equals( ConnectionState.AWAITING_AUTHENTICATION ) ) { + String errMsg = "Your message timed out because you\'re not authenticated. Have you called login()?"; + onError(Topic.ERROR, Event.NOT_AUTHENTICATED, errMsg); + return; + } } } diff --git a/src/main/java/io/deepstream/JavaEndpointWebsocket.java b/src/main/java/io/deepstream/JavaEndpointWebsocket.java index f4cc7bf..088d9f6 100644 --- a/src/main/java/io/deepstream/JavaEndpointWebsocket.java +++ b/src/main/java/io/deepstream/JavaEndpointWebsocket.java @@ -26,7 +26,9 @@ class JavaEndpointWebsocket implements Endpoint { @Override public void send(String message) { - this.websocket.send( message ); + if (this.websocket.isOpen()) { + this.websocket.send(message); + } } @Override