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

GrpcSslConfigurer beans are activated when no `grpc-netty` is present

Open
#4,169 1 comment 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

Describe the bug
Currently grpc-netty is marked as optional dependency of Spring Cloud Gateway server. jsonToGRPCFilterFactory and gRPCSSLContext beans from the looks of it are also only used for functionality which is not really mandatory.

The problem is that if grpc-api dependency is added to the Spring Cloud Gateway server project (though some external requirement), those GRPC beans get activated which then causes java.lang.NoClassDefFoundError: io/grpc/netty/NettyChannelBuilder.

That's because https://github.com/spring-cloud/spring-cloud-gateway/blob/dd5da258debd06dfb01d6c6966b674b8eaba2491/spring-cloud-gateway-server-webflux/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java#L372 and https://github.com/spring-cloud/spring-cloud-gateway/blob/dd5da258debd06dfb01d6c6966b674b8eaba2491/spring-cloud-gateway-server-webflux/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java#L381 relies on io.grpc.Channel which is included in grpc-api.

This produces all sorts of issues when gateway is used with 3rd party dependencies. For example: https://github.com/spring-cloud/spring-cloud-gateway/issues/2769

The only workaround in such case is to include full grpc-netty dependency even if it is never really used by the gateway.

IMHO, much better solution would be for these beans to rely on io.grpc.netty.GrpcSslContexts or io.grpc.netty.NettyChannelBuilder which is actually used in GrpcSslConfigurer.

Sample
Create standard Spring Cloud Gateway server project and add:

        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-api</artifactId>
        </dependency>

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 in spring-cloud-gateway-server-webflux/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java around lines 372 and 381, and inspect the GrpcSslConfigurer bean conditions. Reproduce the issue by adding grpc-api without grpc-netty to a standard Gateway server project. Done means the GRPC beans do not activate and the gateway starts without the NoClassDefFoundError.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.