@@ -117,13 +117,16 @@ public Response send(Request request, boolean reSend, long timeout) throws SQLEx
117117 try {
118118 connectionManager .getCurrentClient ().send (reqString );
119119 } catch (WebsocketNotConnectedException e ) {
120- connectionManager .handleConnectionException (false , this );
121120 try {
121+ connectionManager .handleConnectionException (this );
122122 if (!reSend ) {
123123 inFlightRequest .remove (request .getAction (), request .id ());
124- throw new SQLException ( "reconnect, need to resend " + request . getAction () + " msg" );
124+ throw TSDBError . createSQLException ( TSDBErrorNumbers . ERROR_CONNECTION_CLOSED );
125125 }
126126 connectionManager .getCurrentClient ().send (reqString );
127+ } catch (SQLException ex ) {
128+ inFlightRequest .remove (request .getAction (), request .id ());
129+ throw ex ;
127130 } catch (Exception ex ) {
128131 inFlightRequest .remove (request .getAction (), request .id ());
129132 throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_RESTFul_Client_IOException , e .getMessage ());
@@ -135,7 +138,11 @@ public Response send(Request request, boolean reSend, long timeout) throws SQLEx
135138 try {
136139 response = responseFuture .get ();
137140 handleTaosdError (response );
138- } catch (InterruptedException | ExecutionException e ) {
141+ } catch (InterruptedException e ) {
142+ Thread .currentThread ().interrupt ();
143+ inFlightRequest .remove (request .getAction (), request .id ());
144+ throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_QUERY_TIMEOUT , e .getMessage ());
145+ } catch (ExecutionException e ) {
139146 inFlightRequest .remove (request .getAction (), request .id ());
140147 throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_QUERY_TIMEOUT , e .getMessage ());
141148 }
@@ -193,8 +200,8 @@ public Response send(String action, long reqId, long resultId, long type, byte[]
193200 Utils .retainByteBuf (buffer );
194201 connectionManager .getCurrentClient ().send (buffer );
195202 } catch (WebsocketNotConnectedException e ) {
196- connectionManager .handleConnectionException (false , this );
197203 try {
204+ connectionManager .handleConnectionException (this );
198205 Utils .retainByteBuf (buffer );
199206 connectionManager .getCurrentClient ().send (buffer );
200207 } catch (Exception ex ) {
@@ -210,7 +217,11 @@ public Response send(String action, long reqId, long resultId, long type, byte[]
210217 try {
211218 response = responseFuture .get ();
212219 handleTaosdError (response );
213- } catch (InterruptedException | ExecutionException e ) {
220+ } catch (InterruptedException e ) {
221+ Thread .currentThread ().interrupt ();
222+ inFlightRequest .remove (action , reqId );
223+ throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_QUERY_TIMEOUT , e .getMessage ());
224+ } catch (ExecutionException e ) {
214225 inFlightRequest .remove (action , reqId );
215226 throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_QUERY_TIMEOUT , e .getMessage ());
216227 }
@@ -243,7 +254,7 @@ public void sendFetchBlockAsync(long reqId, long resultId) throws SQLException {
243254 Utils .retainByteBuf (buffer );
244255 connectionManager .getCurrentClient ().send (buffer );
245256 } catch (WebsocketNotConnectedException e ) {
246- connectionManager .handleConnectionException (false , this );
257+ connectionManager .handleConnectionException (this );
247258 throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_STATEMENT_CLOSED ,
248259 "Websocket reconnected, but the result set is closed" );
249260 } finally {
@@ -276,13 +287,20 @@ public Response send(String action, long reqId, ByteBuf buffer, boolean resend,
276287 Utils .retainByteBuf (buffer );
277288 connectionManager .getCurrentClient ().send (buffer );
278289 } catch (WebsocketNotConnectedException e ) {
279- connectionManager .handleConnectionException (false , this );
290+ try {
291+ connectionManager .handleConnectionException (this );
292+ } catch (SQLException ex ) {
293+ inFlightRequest .remove (action , reqId );
294+ throw ex ;
295+ }
296+
297+ if (!resend ) {
298+ inFlightRequest .remove (action , reqId );
299+ throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_CONNECTION_CLOSED );
300+ }
301+
280302 try {
281303 Utils .retainByteBuf (buffer );
282- if (!resend ) {
283- inFlightRequest .remove (action , reqId );
284- throw new SQLException ("reconnect, need to resend " + action + " msg" );
285- }
286304 connectionManager .getCurrentClient ().send (buffer );
287305 } catch (Exception ex ) {
288306 inFlightRequest .remove (action , reqId );
@@ -299,9 +317,13 @@ public Response send(String action, long reqId, ByteBuf buffer, boolean resend,
299317 try {
300318 response = responseFuture .get ();
301319 handleTaosdError (response );
302- } catch (InterruptedException | ExecutionException e ) {
320+ } catch (InterruptedException e ) {
321+ Thread .currentThread ().interrupt ();
303322 inFlightRequest .remove (action , reqId );
304323 throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_QUERY_TIMEOUT , e .getMessage ());
324+ } catch (ExecutionException e ) {
325+ inFlightRequest .remove (action , reqId );
326+ throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_QUERY_TIMEOUT , e .getMessage ());
305327 }
306328 return response ;
307329 }
@@ -353,9 +375,13 @@ public Response sendWithoutRetry(Request request, long timeout) throws SQLExcept
353375 completableFuture , timeout , TimeUnit .MILLISECONDS , reqString );
354376 try {
355377 response = responseFuture .get ();
356- } catch (InterruptedException | ExecutionException e ) {
357- inFlightRequest .remove (request .getAction (), request .id ());
378+ } catch (InterruptedException e ) {
379+ Thread .currentThread ().interrupt ();
380+ throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_QUERY_TIMEOUT , e .getMessage ());
381+ } catch (ExecutionException e ) {
358382 throw TSDBError .createSQLException (TSDBErrorNumbers .ERROR_QUERY_TIMEOUT , e .getMessage ());
383+ } finally {
384+ inFlightRequest .remove (request .getAction (), request .id ());
359385 }
360386 return response ;
361387 }
@@ -374,7 +400,7 @@ public void sendWithoutResponse(Request request) throws SQLException {
374400 try {
375401 connectionManager .getCurrentClient ().send (request .toString ());
376402 } catch (WebsocketNotConnectedException e ) {
377- connectionManager .handleConnectionException (false , this );
403+ connectionManager .handleConnectionException (this );
378404 try {
379405 connectionManager .getCurrentClient ().send (request .toString ());
380406 } catch (Exception ex ) {
0 commit comments