spring-cloud / spring-cloud/spring-cloud-gateway
GrpcSslConfigurer beans are activated when no `grpc-netty` is present
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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