@@ -183,14 +183,12 @@ public CompletionStage<BoltConnection> clear() {
183
183
@ Override
184
184
public CompletionStage <Void > flush (ResponseHandler handler ) {
185
185
return delegate .flush (new ResponseHandler () {
186
- private Throwable error ;
186
+ boolean notifyHandler = true ;
187
187
188
188
@ Override
189
189
public void onError (Throwable throwable ) {
190
- if (error == null ) {
191
- error = handledError (throwable );
192
- handler .onError (error );
193
- }
190
+ handler .onError (handledError (throwable , notifyHandler ));
191
+ notifyHandler = false ;
194
192
}
195
193
196
194
@ Override
@@ -306,34 +304,36 @@ public boolean telemetrySupported() {
306
304
return delegate .telemetrySupported ();
307
305
}
308
306
309
- private Throwable handledError (Throwable receivedError ) {
307
+ private Throwable handledError (Throwable receivedError , boolean notifyHandler ) {
310
308
var error = FutureUtil .completionExceptionCause (receivedError );
311
309
312
- if (error instanceof ServiceUnavailableException ) {
313
- return handledServiceUnavailableException ((( ServiceUnavailableException ) error ) );
314
- } else if (error instanceof ClientException ) {
315
- return handledClientException ((( ClientException ) error ) );
316
- } else if (error instanceof TransientException ) {
317
- return handledTransientException ((( TransientException ) error ) );
310
+ if (error instanceof ServiceUnavailableException exception ) {
311
+ return handledServiceUnavailableException (exception , notifyHandler );
312
+ } else if (error instanceof ClientException exception ) {
313
+ return handledClientException (exception , notifyHandler );
314
+ } else if (error instanceof TransientException exception ) {
315
+ return handledTransientException (exception , notifyHandler );
318
316
} else {
319
317
return error ;
320
318
}
321
319
}
322
320
323
- private Throwable handledServiceUnavailableException (ServiceUnavailableException e ) {
324
- routingTableHandler .onConnectionFailure (serverAddress ());
321
+ private Throwable handledServiceUnavailableException (ServiceUnavailableException e , boolean notifyHandler ) {
322
+ if (notifyHandler ) {
323
+ routingTableHandler .onConnectionFailure (serverAddress ());
324
+ }
325
325
return new SessionExpiredException (format ("Server at %s is no longer available" , serverAddress ()), e );
326
326
}
327
327
328
- private Throwable handledTransientException (TransientException e ) {
328
+ private Throwable handledTransientException (TransientException e , boolean notifyHandler ) {
329
329
var errorCode = e .code ();
330
- if (Objects .equals (errorCode , "Neo.TransientError.General.DatabaseUnavailable" )) {
330
+ if (Objects .equals (errorCode , "Neo.TransientError.General.DatabaseUnavailable" ) && notifyHandler ) {
331
331
routingTableHandler .onConnectionFailure (serverAddress ());
332
332
}
333
333
return e ;
334
334
}
335
335
336
- private Throwable handledClientException (ClientException e ) {
336
+ private Throwable handledClientException (ClientException e , boolean notifyHandler ) {
337
337
if (isFailureToWrite (e )) {
338
338
// The server is unaware of the session mode, so we have to implement this logic in the driver.
339
339
// In the future, we might be able to move this logic to the server.
@@ -349,7 +349,9 @@ private Throwable handledClientException(ClientException e) {
349
349
null );
350
350
}
351
351
case WRITE -> {
352
- routingTableHandler .onWriteFailure (serverAddress ());
352
+ if (notifyHandler ) {
353
+ routingTableHandler .onWriteFailure (serverAddress ());
354
+ }
353
355
return new SessionExpiredException (
354
356
format ("Server at %s no longer accepts writes" , serverAddress ()));
355
357
}
0 commit comments