2

I'm doing a test project in which I'm trying to implement AOT with GRPC, it can compile the image through paketo but when running the generated image it shows the error: "Native reflection configuration for io.grpc.netty. shaded.io.netty.channel.socket.nio.NioSocketChannel.() is missing." I tried to guide the compilation of this class through @TypeHint(types = NioServerSocketChannel.class) but it didn't work.

Project: https://github.com/thukabjj/spring-boot-grpc/tree/main/simulacao

Print image execution

Has anyone experienced a similar error?

2 Answers2

1

Yes, your hint is missing the method part... This is the hints i need to make my grpc work (the last one is for the error you describle)

@TypeHints({ //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerIndexField",
            fields = @FieldHint(name = "producerIndex", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueProducerLimitField",
            fields = @FieldHint(name = "producerLimit", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueueConsumerIndexField",
            fields = @FieldHint(name = "consumerIndex", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueProducerFields",
            fields = @FieldHint(name = "producerIndex", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields",
            fields = @FieldHint(name = "producerLimit", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.util.internal.shaded.org.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields",
            fields = @FieldHint(name = "consumerIndex", allowUnsafeAccess = true)), //
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.buffer.AbstractByteBufAllocator", access = AccessBits.ALL),
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.channel.ReflectiveChannelFactory", access = AccessBits.ALL),
    @TypeHint(typeNames = "io.grpc.netty.shaded.io.netty.channel.socket.nio.NioSocketChannel", methods = @MethodHint(name = "<init>")) })
  • With your approach i had another error on execution of docker image: "Native reflection configuration for br.com.agrupamento.AgrupamentoServiceGrpc.newBlockingStub(io.grpc.Channel) is missing" – Arthur Alves Aug 26 '21 at 16:20
  • Some or all of these should be fixed in grpc-java [1.41.0](https://github.com/grpc/grpc-java/releases/tag/v1.41.0). – ST-DDT Sep 24 '21 at 17:41
  • The only remaining issues should be from the generated proto/grpc-service code. I plan to add a graalvm native hint provider as part of [yidongnan/grpc-spring-boot-starter#577](https://github.com/yidongnan/grpc-spring-boot-starter/issues/577). I'm not sure yet, whether I will do that in grpc-spring-boot-starter, grpc-java or protobuf itself. – ST-DDT Sep 24 '21 at 17:50
0

Spring Boot 3.0 and Spring 6.0 have built in support for AOT, so you don't have to work as hard. You currently need to patch the autoconfig metadata and add one hint, but over time I expect those chores to be absorbed upstream. Here's the metadata (src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports):

net.devh.boot.grpc.server.autoconfigure.GrpcAdviceAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcHealthServiceAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataConsulConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataEurekaConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataNacosConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcMetadataZookeeperConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcReflectionServiceAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerMetricAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerSecurityAutoConfiguration
net.devh.boot.grpc.server.autoconfigure.GrpcServerTraceAutoConfiguration

and here is the application including the hint:

@SpringBootApplication
@ImportRuntimeHints(DemoApplicationRuntimeHints.class)
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

class DemoApplicationRuntimeHints implements RuntimeHintsRegistrar {

    @Override
    public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
        hints.reflection().registerType(AbstractByteBufAllocator.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_METHODS);
    }

}

There's a complete sample here.

Dave Syer
  • 56,583
  • 10
  • 155
  • 143