gRPC-Java: How to catch StatusRuntimeException on Server side

1,295 views
Skip to first unread message

Xiaojun Zhang

unread,
Jul 26, 2022, 10:22:52 AM7/26/22
to grpc.io
We had an issue today where gRPC server received a corrupted protobuf message.
Then it seemed to disconnect the client. While i can't reproduce this error is there a way to catch such exception on the service side? i.e. in onNext()

2022-07-26 10:39:15.006 ERROR 60123 --- [ult-executor-39] io.grpc.internal.SerializingExecutor     : Exception while executing runnable io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1MessagesAvailable@3a33e25f

io.grpc.StatusRuntimeException: INTERNAL: Invalid protobuf byte sequence
        at io.grpc.Status.asRuntimeException(Status.java:525) ~[grpc-api-1.35.0.jar:1.35.0]
        at io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller.parse(ProtoLiteUtils.java:218) ~[grpc-protobuf-lite-1.35.0.jar:1.35.0]
        at io.grpc.protobuf.lite.ProtoLiteUtils$MessageMarshaller.parse(ProtoLiteUtils.java:118) ~[grpc-protobuf-lite-1.35.0.jar:1.35.0]
        at io.grpc.MethodDescriptor.parseRequest(MethodDescriptor.java:307) ~[grpc-api-1.35.0.jar:1.35.0]
        at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.messagesAvailableInternal(ServerCallImpl.java:309) ~[grpc-core-1.35.0.jar:1.35.0]
        at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.messagesAvailable(ServerCallImpl.java:292) ~[grpc-core-1.35.0.jar:1.35.0]
        at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1MessagesAvailable.runInContext(ServerImpl.java:782) ~[grpc-core-1.35.0.jar:1.35.0]
        at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) ~[grpc-core-1.35.0.jar:1.35.0]
        at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) ~[grpc-core-1.35.0.jar:1.35.0]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_71]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_71]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_71]

Sergii Tkachenko

unread,
Jul 26, 2022, 7:54:37 PM7/26/22
to grpc.io
Hey Xiaojun,

As far as I understand, this happens down the stack, before your server handlers are triggered. And it's normal for gRPC to fail RPC on errors, including demarshalling errors.

What you'd need is to insert your code prior to protobuf getting unpacked, and handle it manually. Take a look at this StackOverflow answer written by on of our engineers: soap - How can I fully intercept a gRPC java unary call, on the client, and on the server? - Stack Overflow, and this issue: Access unparsed data in interceptor? · Issue #1403 · grpc/grpc-java.

Best regards,
Sergii

Reply all
Reply to author
Forward
0 new messages