spring-cloud / spring-cloud/spring-cloud-gateway

JsonToGrpcGatewayFilterFactory uses blocking gRPC calls

Open
#3,880 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting JsonToGrpcGatewayFilterFactory and its callGRPCServer() method, focusing on the ClientCalls.blockingUnaryCall usage within the reactive chain. Verify that gRPC work no longer blocks Netty event-loop threads and that server errors are propagated to the client without hanging connections.

Written by the indexing model from the issue text.

Assessment

Tech stack
grpc, java
Domain
api, backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.