Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientInterceptor not applied to gRPC Channel #10439

Closed
vladykin opened this issue Jul 2, 2020 · 4 comments · Fixed by #10533
Closed

ClientInterceptor not applied to gRPC Channel #10439

vladykin opened this issue Jul 2, 2020 · 4 comments · Fixed by #10533
Assignees
Labels
area/grpc gRPC kind/bug Something isn't working
Milestone

Comments

@vladykin
Copy link

vladykin commented Jul 2, 2020

Describe the bug

I have a problem adding an interceptor to gRPC Channel instantiated by Quarkus.
Here is a minimal reproducer.

package org.acme;

import io.grpc.*;
import io.quarkus.grpc.runtime.annotations.GrpcService;
import io.quarkus.runtime.Startup;
import io.quarkus.runtime.StartupEvent;

import javax.enterprise.event.Observes;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;

@Startup
public class ExampleApp {

    private static boolean interceptorInstatiated = false;

    public void onStart(@Observes StartupEvent ev,
                        @GrpcService("hello") Channel helloService) {

        System.out.printf("Interceptor instantiated: %s%n", interceptorInstatiated);
    }

    @Produces
    public static ClientInterceptor grpcInterceptor() {
        interceptorInstatiated = true;
        return new ClientInterceptor() {
            @Override
            public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
                return next.newCall(method, callOptions);
            }
        };
    }
}

Expected behavior
I expect ClientInterceptor to be instantiated and registered with Channel. In io.quarkus.grpc.runtime.supports.Channels.createChannel I see code instantiating and adding interceptors. And similar approach works for ServerInterceptor when implementing gRPC server.

Actual behavior
ClientInterceptor is not instantiated.
Program prints: Interceptor instantiated: false

To Reproduce
Steps to reproduce the behavior:

  1. Create empty Quarkus project with gRPC extension
  2. Paste the ExampleApp class as shown above
  3. Run it and see Interceptor instantiated: false

Configuration

# Add your application.properties here, if applicable.
quarkus.grpc.clients.hello.host=localhost
quarkus.grpc.clients.hello.port=50051

Environment (please complete the following information):

  • Output of uname -a or ver: Linux laptop 5.4.48-gentoo #1 SMP Sat Jun 27 23:10:36 MSK 2020 x86_64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz GenuineIntel GNU/Linux
  • Output of java -version:
openjdk version "11.0.6" 2020-01-14 LTS
OpenJDK Runtime Environment Zulu11.37+17-CA (build 11.0.6+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.37+17-CA (build 11.0.6+10-LTS, mixed mode)
  • GraalVM version (if different from Java): not using GraalVM
  • Quarkus version or git rev: 1.5.2.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Apache Maven 3.6.2
@vladykin vladykin added the kind/bug Something isn't working label Jul 2, 2020
@quarkusbot quarkusbot added the area/grpc gRPC label Jul 2, 2020
@quarkusbot
Copy link

/cc @michalszynkiewicz, @cescoffier

@cescoffier
Copy link
Member

Can it be related to the @Startup? Did you try with exposing an @ApplicationScoped bean (as a class) ?

@vladykin
Copy link
Author

vladykin commented Jul 3, 2020

I tried various scope annotation combinations on the ExampleApp and the grpcInterceptor() method. Also tried extracting interceptor as a separate class:

package org.acme;

import io.grpc.*;

import javax.inject.Singleton;

@Singleton
public class MyInterceptor implements ClientInterceptor {

  public MyInterceptor() {
    ExampleApp.interceptorInstatiated = true;
  }

  @Override
  public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
    return next.newCall(method, callOptions);
  }
}

But it did not help. Interceptor is still not instantiated.

@cescoffier
Copy link
Member

So definitely a bug. Thanks for the report, we will look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/grpc gRPC kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants