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

Interceptor compression not propagated to real handler #1557

Open
raritzu opened this issue Jul 14, 2019 · 2 comments
Open

Interceptor compression not propagated to real handler #1557

raritzu opened this issue Jul 14, 2019 · 2 comments
Assignees

Comments

@raritzu
Copy link

raritzu commented Jul 14, 2019

ServerCall.setCompression lost due to dagger.grpc.server.ProxyServerCallHandler.ServerCallAdapter
not propagated to delegate, example:

public class CompressionInterceptor implements ServerInterceptor {
    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,
                                                                 ServerCallHandler<ReqT, RespT> next) {
        call.setCompression("gzip");
        return next.startCall(call, headers);
    }
}
@ronshapiro
Copy link

Can you provide a working example? It's a little hard to tell what you're reporting without some more context

@raritzu
Copy link
Author

raritzu commented Jul 15, 2019

So basically the problem is with the Grpc Server that is setup with Dagger (client initiating compression works fine). A very basic simple example would be a server, taken from the Dagger article (https://dagger.dev/grpc/servers.html):

public class CompressingGreeterServer {
    private static final Logger logger = Logger.getLogger(CompressingGreeterServer.class.getName());

    @Module(includes = {
            GreeterModule.class,
    })
    static abstract class GreeterGrpcModule {
        @Binds
        abstract GreeterServiceDefinition provideGreeterServiceDefinition(ServerComponent serverComponent);

        @Provides
        @ForGrpcService(GreeterGrpc.class)
        static List<? extends ServerInterceptor> provideInterceptors() {
            return Arrays.asList(new ServerInterceptor() {
                @Override
                public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
                    call.setCompression("gzip");
                    return next.startCall(call, headers);
                }
            });
        }
    }

    @Singleton
    @Component(modules = {
            GreeterUnscopedGrpcServiceModule.class,
            GreeterGrpcModule.class,
            NettyServerModule.class,
    })
    interface ServerComponent extends GreeterServiceDefinition {
        Server server();
    }

    private void start() throws IOException, InterruptedException {
        int port = 50051;
        ServerComponent component =
                DaggerCompressingGreeterServer_ServerComponent.builder()
                        .nettyServerModule(NettyServerModule.bindingToPort(port))
                        .build();
        final Server server = component.server();
        server.start();

        Runtime.getRuntime()
                .addShutdownHook(
                        new Thread(
                                () -> {
                                    // Use stderr here since the logger may have been reset by its JVM shutdown hook.
                                    System.err.println("*** shutting down Auth Server since JVM is shutting down");
                                    server.shutdown();
                                    System.err.println("*** server shut down");
                                }));
        server.awaitTermination();
        logger.info("Server started, listening on " + port);
    }

    public static void main(String[] args) throws IOException, InterruptedException {
        CompressingGreeterServer server = new CompressingGreeterServer();
        server.start();
    }
}

And the Greeter class:

@GrpcService(grpcClass = GreeterGrpc.class)
public class Greeter extends GreeterGrpc.GreeterImplBase {
    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
        HelloReply reply = HelloReply.newBuilder().setMessage("Hello: " + request.getName()).build();
        responseObserver.onNext(reply);
        responseObserver.onCompleted();
    }
}

But because dagger.grpc.server.ProxyServerCallHandler.ServerCallAdapter is not delegating the setCompression call, compression never happens. Solution is simple: delegate.setCompression(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants