@@ -40,6 +40,7 @@ private enum ConnectionState {
4040 CLOSED
4141 }
4242
43+
4344 private final static String KEEP_ALIVE_PAYLOAD = ":keepalive\n " ;
4445 private final static Integer CONNECT_TIMEOUT = 30000 ;
4546 private final static Integer SOCKET_TIMEOUT = 70000 ;
@@ -109,26 +110,31 @@ private void connectAndLoop(URI uri, CountDownLatch signal) {
109110 while (isOpen () && !Thread .currentThread ().isInterrupted ()) {
110111 try {
111112 handleMessage (readMessageAsString (reader ));
112- } catch (EOFException exc ) {
113- // This is when ably closes the connection on their end. IE: an invalid or expired token.
113+ } catch (EOFException | SocketTimeoutException exc ) {
114+ // EOFException: This is when ably closes the connection on their end. IE: an invalid or expired token.
115+ // SocketTimeoutException: KeepAlive expired
116+ _log .warn (exc .getMessage ());
114117 _statusCallback .apply (StatusMessage .RETRYABLE_ERROR );
115118 return ;
116- } catch (SocketTimeoutException exc ) { // KeepAlive expired
117- _statusCallback . apply ( StatusMessage . RETRYABLE_ERROR );
118- } catch ( SocketException exc ) { // Connection closed by us
119+ } catch (SocketException exc ) {
120+ _log . warn ( exc . getMessage () );
121+
119122 if ("Socket closed" .equals (exc .getMessage ())) {
123+ // Connection closed by us
120124 _statusCallback .apply (StatusMessage .FORCED_STOP );
121125 return ;
122126 }
123127
124- throw exc ; // If it's not a socket closed (caused by us), rethrow the exception
128+ // Connection closed by server
129+ _statusCallback .apply (StatusMessage .RETRYABLE_ERROR );
130+ return ;
125131 }
126132 }
127133 } catch (Exception e ) {
128134 _log .error (e .getMessage ());
135+
129136 _statusCallback .apply (StatusMessage .NONRETRYABLE_ERROR );
130- }
131- finally {
137+ } finally {
132138 try {
133139 _ongoingResponse .get ().close ();
134140 } catch (IOException e ) {
0 commit comments