From 60474f2a75dedd69a6385ef2421ffc856a2fc693 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Wed, 2 Oct 2024 18:09:08 +0200 Subject: [PATCH] Fix errors not handled when closed --- .../rockserver/core/server/GrpcServer.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java b/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java index 46f1437..ad0b325 100644 --- a/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java +++ b/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java @@ -772,15 +772,20 @@ public class GrpcServer extends Server { if (ex instanceof CompletionException exx) { handleError(responseObserver, exx.getCause()); } else { - if (ex instanceof RocksDBException e) { - responseObserver.onError(Status.INTERNAL - .withDescription(e.getLocalizedMessage()) - .withCause(e) - .asException()); + var serverResponseObserver = ((ServerCallStreamObserver) responseObserver); + if (!serverResponseObserver.isCancelled()) { + if (ex instanceof RocksDBException e) { + responseObserver.onError(Status.INTERNAL + .withDescription(e.getLocalizedMessage()) + .withCause(e) + .asException()); + } else { + responseObserver.onError(Status.INTERNAL + .withCause(ex) + .asException()); + } } else { - responseObserver.onError(Status.INTERNAL - .withCause(ex) - .asException()); + LOG.error("Unexpected error", ex); } } }