From 2888e30d0bba203dfebe126519e5cc3cee75ecfd Mon Sep 17 00:00:00 2001 From: Tsz-Wo Nicholas Sze Date: Thu, 2 Mar 2023 18:44:25 -0800 Subject: [PATCH] RATIS-1802. GrpcServerProtocolService encounters IllegalStateException: call already closed. --- .../apache/ratis/grpc/server/GrpcServerProtocolService.java | 4 +++- ratis-proto/src/main/proto/Grpc.proto | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java index c1006696be..8a58cdd9cf 100644 --- a/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java +++ b/ratis-grpc/src/main/java/org/apache/ratis/grpc/server/GrpcServerProtocolService.java @@ -92,7 +92,9 @@ StatusRuntimeException wrapException(Throwable e, REQUEST request) { private void handleError(Throwable e, REQUEST request) { GrpcUtil.warn(LOG, () -> getId() + ": Failed " + op + " request " + requestToString(request), e); - responseObserver.onError(wrapException(e, request)); + if (isClosed.compareAndSet(false, true)) { + responseObserver.onError(wrapException(e, request)); + } } private synchronized void handleReply(REPLY reply) { diff --git a/ratis-proto/src/main/proto/Grpc.proto b/ratis-proto/src/main/proto/Grpc.proto index edcd863a19..8b7a7ffa10 100644 --- a/ratis-proto/src/main/proto/Grpc.proto +++ b/ratis-proto/src/main/proto/Grpc.proto @@ -47,7 +47,7 @@ service RaftServerProtocolService { returns(stream ratis.common.InstallSnapshotReplyProto) {} rpc readIndex(ratis.common.ReadIndexRequestProto) - returns(stream ratis.common.ReadIndexReplyProto) {} + returns(ratis.common.ReadIndexReplyProto) {} } service AdminProtocolService {