grpc-spring-boot-starter icon indicating copy to clipboard operation
grpc-spring-boot-starter copied to clipboard

GRpcServicesRegistry#descriptorToServiceMethod not mapping method names

Open tobq opened this issue 3 years ago • 14 comments

org.lognet.springboot.grpc.GRpcServicesRegistry#descriptorToServiceMethod doesn't map the RPC methods, of the form rpc_method_name (snake-case) to the generated java methods, of the form rpcMethodName (camel-case).

This causes the following error to be thrown at run-time:

org.lognet.springboot.grpc.security.SecurityInterceptor$1: Authentication failure.
	at org.lognet.springboot.grpc.security.SecurityInterceptor.interceptCall(SecurityInterceptor.java:147) ~[grpc-spring-boot-starter-4.5.10.jar:na]
	at io.grpc.ServerInterceptors$InterceptCallHandler.startCall(ServerInterceptors.java:244) ~[grpc-api-1.42.0.jar:1.42.0]
	at org.lognet.springboot.grpc.recovery.GRpcExceptionHandlerInterceptor.interceptCall(GRpcExceptionHandlerInterceptor.java:59) ~[grpc-spring-boot-starter-4.5.10.jar:na]
	at io.grpc.ServerInterceptors$InterceptCallHandler.startCall(ServerInterceptors.java:244) ~[grpc-api-1.42.0.jar:1.42.0]
	at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.startWrappedCall(ServerImpl.java:703) ~[grpc-core-1.42.0.jar:1.42.0]
	at io.grpc.internal.ServerImpl$ServerTransportListenerImpl.access$2200(ServerImpl.java:406) ~[grpc-core-1.42.0.jar:1.42.0]
	at io.grpc.internal.ServerImpl$ServerTransportListenerImpl$1HandleServerCall.runInternal(ServerImpl.java:615) ~[grpc-core-1.42.0.jar:1.42.0]
	at io.grpc.internal.ServerImpl$ServerTransportListenerImpl$1HandleServerCall.runInContext(ServerImpl.java:603) ~[grpc-core-1.42.0.jar:1.42.0]
	at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) ~[grpc-core-1.42.0.jar:1.42.0]
	at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133) ~[grpc-core-1.42.0.jar:1.42.0]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:831) ~[na:na]
Caused by: java.lang.IllegalStateException: Method ***rpc_method_name*** not found in service ***org.me.MyGrpcService***
	at org.lognet.springboot.grpc.GRpcServicesRegistry.descriptorToServiceMethod(GRpcServicesRegistry.java:186) ~[grpc-spring-boot-starter-4.5.10.jar:na]
	at org.springframework.util.function.SingletonSupplier.get(SingletonSupplier.java:97) ~[spring-core-5.3.7.jar:5.3.7]
	at org.lognet.springboot.grpc.GRpcServicesRegistry.getGrpServiceMethod(GRpcServicesRegistry.java:120) ~[grpc-spring-boot-starter-4.5.10.jar:na]
	at org.lognet.springboot.grpc.security.SecurityInterceptor.setupGRpcSecurityContext(SecurityInterceptor.java:261) ~[grpc-spring-boot-starter-4.5.10.jar:na]
	at org.lognet.springboot.grpc.security.SecurityInterceptor.interceptCall(SecurityInterceptor.java:143) ~[grpc-spring-boot-starter-4.5.10.jar:na]
	... 12 common frames omitted

tobq avatar Nov 28 '21 18:11 tobq

Please post your proto as a sample

jvmlet avatar Nov 29 '21 17:11 jvmlet

@jvmlet Here's an abstracted version

syntax = "proto3";

package org.tobi;
option java_package = "org.tobi.grpc";
option java_multiple_files = true;

import "....proto";
service MyGrpcService {
  rpc rpc_method_name(org.tobi...) returns (RpcResponse) {};
}

tobq avatar Nov 29 '21 18:11 tobq

@jvmlet seems the problem is the generator, at compile time, compiles to camelCase, however at runtime, the library is not doing this same conversion from snake_case to camelCase

tobq avatar Nov 29 '21 19:11 tobq

Any updates? @jvmlet

tobq avatar Dec 26 '21 09:12 tobq

https://github.com/grpc/grpc-java/issues/8826

jvmlet avatar Jan 12 '22 09:01 jvmlet

@jvmlet I put this hack in place:

    private static final Pattern SNAKE_CASE_PATTERN = Pattern.compile("_");
// ...
        Function<String, ReflectionUtils.MethodFilter> filterFactory = name -> method -> {
            var processedName = SNAKE_CASE_PATTERN.matcher(name).replaceAll("");
            return method.getName().equalsIgnoreCase(processedName);
        };

tobq avatar Jan 12 '22 12:01 tobq

I'm aware about this ;-) , but what about this :

service MyGrpcService {
  rpc rpc_method_name(org.tobi...) returns (RpcResponse) {};
  rpc rpc_mEthod_nAme(org.tobi...) returns (RpcResponse) {};
}

?

jvmlet avatar Jan 12 '22 12:01 jvmlet

@jvmlet ah, so the whole implementation needs to be reworked, because the original implementation simply does an ignoreCase comparison. Anyway, I don't have any cases like this so I will keep my hack in place until the package is patched, as it was completely blocking me

tobq avatar Jan 12 '22 13:01 tobq

You are right... I'll implement your suggestion meanwhile since the original implementation suffers from this anyway. Let's hope grpc java team will provide solution in the nearest future.

jvmlet avatar Jan 12 '22 15:01 jvmlet

@tobq , please try with 4.6.0-SNAPSHOT, I'll keep the issue open meanwhile. may be grpc team will provide the requested API

jvmlet avatar Jan 13 '22 08:01 jvmlet

@jvmlet I get:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'io.github.lognet.grpc-spring-boot:io.github.lognet.grpc-spring-boot.gradle.plugin:4.6.0-SNAPSHOT')
  Searched in the following repositories:
    maven(https://repo.spring.io/milestone)
    maven2(https://repo.spring.io/snapshot)
    Gradle Central Plugin Repository

tobq avatar Jan 13 '22 18:01 tobq

Snapshot version of grpc spring boot gradle plugin is published to sonatype only. Gradle plugins repo doesn't support snapshots. Please add sonatype repo as source for gradle plugins.

jvmlet avatar Jan 13 '22 19:01 jvmlet

https://oss.sonatype.org/#nexus-search;gav~io.github.lognet.grpc-spring-boot~io.github.lognet.grpc-spring-boot.gradle.plugin~~~~kw,versionexpand

jvmlet avatar Jan 13 '22 19:01 jvmlet

@jvmlet I tried

settings.gradle

pluginManagement {
    repositories {
        maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots'
        }
    }
}

build.gradle

plugins {
    id "io.github.lognet.grpc-spring-boot" version '4.6.0-SNAPSHOT'
}

which doesn't work

tobq avatar Jan 22 '22 19:01 tobq