반응형
Error
Spring Boot에서 gRPC를 이용하여 gRPC 서버로 대용량 Request시 아래 에러 발생
io.grpc.StatusRuntimeException: RESOURCE_EXHAUSTED: gRPC message exceeds maximum size 4194304: 11908854
at io.grpc.Status.asRuntimeException(Status.java:526) ~[grpc-api-1.42.2.jar:1.42.2]
at io.grpc.internal.MessageDeframer.processHeader(MessageDeframer.java:391) ~[grpc-core-1.42.2.jar:1.42.2]
at io.grpc.internal.MessageDeframer.deliver(MessageDeframer.java:271) ~[grpc-core-1.42.2.jar:1.42.2]
at io.grpc.internal.MessageDeframer.request(MessageDeframer.java:161) ~[grpc-core-1.42.2.jar:1.42.2]
at io.grpc.internal.AbstractStream$TransportState$1RequestRunnable.run(AbstractStream.java:236) ~[grpc-core-1.42.2.jar:1.42.2]
at io.grpc.netty.shaded.io.grpc.netty.NettyServerStream$TransportState$1.run(NettyServerStream.java:202) ~[grpc-netty-shaded-1.42.2.jar:1.42.2]
at io.grpc.netty.shaded.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) ~[grpc-netty-shaded-1.42.2.jar:1.42.2]
at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) ~[grpc-netty-shaded-1.42.2.jar:1.42.2]
at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:497) ~[grpc-netty-shaded-1.42.2.jar:1.42.2]
at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) ~[grpc-netty-shaded-1.42.2.jar:1.42.2]
at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[grpc-netty-shaded-1.42.2.jar:1.42.2]
at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[grpc-netty-shaded-1.42.2.jar:1.42.2]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
반응형
Solution
- gRPC 서버에서 요청 메시지의 default size limit은 4MB이기 때문에 에러남
Message Mas Size를 늘리는 방법은 여러가지가 있는데 원래는 아래와 같이 ManagedChannel Bean을 생성할 때 설정값을 설정해줘야 함.
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 9089).usePlaintext().maxInboundMessageSize(Integer.MAX_VALUE).build();
하지만 grpc-server-spring-boot-starter를 사용하여 autoconfigure를 이용하고 있기 때문에 라이브러리 내에 GrpcServerProperties를 들여다봤는데
maxInboundMessageSize라는 변수를 프로퍼티에서 관리함.
따라서 application.yaml파일에 아래 설정만 추가해 주면됨
grpc:
server:
port: 9090
max-inbound-message-size: 1500000 #byte
Thank you!
반응형