spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

JsonToGrpcGatewayFilterFactory uses blocking gRPC calls

Open nxzzhe-ai opened this issue 4 months ago • 0 comments

Bug Report Component: JsonToGrpcGatewayFilterFactory Version: All versions supporting gRPC (3.1.0+) Severity: Critical (Performance)

Description The default implementation of JsonToGrpcGatewayFilterFactory uses blocking gRPC calls (ClientCalls.blockingUnaryCall) within the reactive processing chain, which severely blocks Netty event loop threads and fundamentally violates the reactive programming model that Spring Cloud Gateway is built upon.

The JSONToGRPC GatewayFilter Factory is designed to convert a JSON payload to a gRPC request. However, its current implementation makes blocking calls directly on the event loop thread, crippling the gateway's ability to handle concurrent requests efficiently.

Problem Analysis In the current implementation, the critical issue is in the callGRPCServer() method:

private Function<JsonNode, DynamicMessage> callGRPCServer() {
    return jsonRequest -> {
        try {
            byte[] request = objectWriter.writeValueAsBytes(jsonRequest);
            // ⚠️ Blocking call on event loop thread
            return ClientCalls.blockingUnaryCall(clientCall, DynamicMessage.parseFrom(descriptor, request));
        }
        // ...
    };
}

This implementation:

Uses synchronous (blocking APIs) which block thread execution until the server responds with a result Runs blocking operations directly on Netty event loop threads Prevents the gateway from achieving high throughput despite being built on reactive foundations Causes the connection to hang when gRPC sends an error response, as the error is never properly propagated to the clien

nxzzhe-ai avatar Aug 11 '25 16:08 nxzzhe-ai