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

Native image generation fails when adding a dependency with io.micronaut.gcp:micronaut-gcp-tracing #532

Open
codependent opened this issue Dec 24, 2021 · 6 comments
Labels
relates-to: graal type: bug Something isn't working

Comments

@codependent
Copy link

Expected Behavior

A native image should be generated

Actual Behaviour

The following error is shown:

[application:29]     analysis:  53,123.08 ms,  4.90 GB
Error: Classes that should be initialized at run time got initialized during image building:
 io.grpc.netty.shaded.io.netty.handler.ssl.PemPrivateKey the class was requested to be initialized at run time (subtype of io.grpc.netty.shaded.io.netty.util.AbstractReferenceCounted). To see why io.grpc.netty.shaded.io.netty.handler.ssl.PemPrivateKey got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.handler.ssl.PemPrivateKey
io.grpc.netty.shaded.io.netty.buffer.PooledByteBuf the class was requested to be initialized at run time (subtype of io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.grpc.netty.shaded.io.netty.buffer.PooledByteBuf got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.PooledByteBuf
io.grpc.netty.shaded.io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.grpc.netty.shaded.io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf
io.grpc.netty.shaded.io.netty.buffer.UnpooledDirectByteBuf the class was requested to be initialized at run time (subtype of io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.grpc.netty.shaded.io.netty.buffer.UnpooledDirectByteBuf got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.UnpooledDirectByteBuf
io.grpc.netty.shaded.io.netty.buffer.AbstractPooledDerivedByteBuf the class was requested to be initialized at run time (subtype of io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.grpc.netty.shaded.io.netty.buffer.AbstractPooledDerivedByteBuf got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.AbstractPooledDerivedByteBuf
io.grpc.netty.shaded.io.netty.buffer.ByteBufUtil the class was requested to be initialized at run time (from jar:file:///home/app/libs/grpc-netty-shaded-1.39.0.jar!/META-INF/native-image/io.netty/buffer/native-image.properties with 'io.grpc.netty.shaded.io.netty.buffer.ByteBufUtil'). To see why io.grpc.netty.shaded.io.netty.buffer.ByteBufUtil got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.ByteBufUtil
io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf the class was requested to be initialized at run time (from jar:file:///home/app/libs/grpc-netty-shaded-1.39.0.jar!/META-INF/native-image/io.netty/buffer/native-image.properties with 'io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf'). To see why io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf
io.grpc.netty.shaded.io.netty.handler.ssl.PemValue the class was requested to be initialized at run time (subtype of io.grpc.netty.shaded.io.netty.util.AbstractReferenceCounted). To see why io.grpc.netty.shaded.io.netty.handler.ssl.PemValue got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.handler.ssl.PemValue
io.grpc.netty.shaded.io.netty.util.AbstractReferenceCounted the class was requested to be initialized at run time (from jar:file:///home/app/libs/grpc-netty-shaded-1.39.0.jar!/META-INF/native-image/io.netty/common/native-image.properties with 'io.grpc.netty.shaded.io.netty.util.AbstractReferenceCounted'). To see why io.grpc.netty.shaded.io.netty.util.AbstractReferenceCounted got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.util.AbstractReferenceCounted
io.grpc.netty.shaded.io.netty.buffer.ByteBufAllocator the class was requested to be initialized at run time (from jar:file:///home/app/libs/grpc-netty-shaded-1.39.0.jar!/META-INF/native-image/io.netty/buffer/native-image.properties with 'io.grpc.netty.shaded.io.netty.buffer.ByteBufAllocator'). To see why io.grpc.netty.shaded.io.netty.buffer.ByteBufAllocator got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.ByteBufAllocator
io.grpc.netty.shaded.io.netty.buffer.PooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.grpc.netty.shaded.io.netty.buffer.PooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.PooledUnsafeDirectByteBuf
io.grpc.netty.shaded.io.netty.buffer.UnpooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.grpc.netty.shaded.io.netty.buffer.UnpooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.UnpooledUnsafeDirectByteBuf
io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator the class was requested to be initialized at run time (from jar:file:///home/app/libs/grpc-netty-shaded-1.39.0.jar!/META-INF/native-image/io.netty/buffer/native-image.properties with 'io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator'). To see why io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.PooledByteBufAllocator
io.grpc.netty.shaded.io.netty.buffer.UnpooledHeapByteBuf the class was requested to be initialized at run time (subtype of io.grpc.netty.shaded.io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.grpc.netty.shaded.io.netty.buffer.UnpooledHeapByteBuf got initialized use --trace-class-initialization=io.grpc.netty.shaded.io.netty.buffer.UnpooledHeapByteBuf

Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
[application:29]      [total]:  59,798.31 ms,  4.90 GB
# Printing build artifacts to: /home/app/application.build_artifacts.txt
Error: Image build request failed with exit status 1


> Task :dockerBuildNative FAILED

Steps To Reproduce

  1. Clone the repository from https://github.com/codependent/micro-tracing
  2. Run ./gradlew dockerBuildNative
  3. The error is shown in the logs
  4. Comment out this dependency: implementation("io.micronaut.gcp:micronaut-gcp-tracing")
  5. Run ./gradlew dockerBuildNative
  6. This time it works fine

Environment Information

MacOS
Java 17 Temurin
Buiding using Docker

Example Application

https://github.com/codependent/micro-tracing

Version

3.2.3

@j1cs
Copy link
Contributor

j1cs commented Mar 16, 2022

I don't know how can make it with gradle but with maven when you add this two configuration you'll not have that problem.

  <profiles>
    <profile>
      <id>graalvm</id>
      <dependencies>
        <dependency>
          <groupId>com.google.cloud</groupId>
          <artifactId>native-image-support</artifactId>
          <scope>compile</scope>
          <version>${native-image-support.version}</version>
        </dependency>
      </dependencies>
    </profile>
  </profiles>

<plugins>
 <build>
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.4</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <filters>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </plugin>
    </plugins>
  </build>

@snorremd
Copy link

snorremd commented Jul 8, 2022

For the record. I'm seeing the same issue with the following versions:

micronaut-gcp: 3.4
graal-vm: 22.1.0
native-image-support: 0.12.11

I've tried with and without the native-image-support dependency for native image compilation. Including it just produces a different error.

The gradle dependency code:

nativeImageCompileOnly("com.google.cloud:native-image-support")

The graalvm output error:

Fatal error: org.graalvm.compiler.debug.GraalError: 
com.oracle.graal.pointsto.constraints.UnsupportedFeatureException:
Detected a PlatformManagedObject (a MXBean defined by the virtual machine) in the image heap.
This bean is introspecting the VM that runs the image builder, i.e., a VM instance that is no longer available at image runtime.
Class of disallowed object: com.sun.management.internal.HotSpotDiagnostic
To see how this object got instantiated use --trace-object-instantiation=com.sun.management.internal.HotSpotDiagnostic.
The object was probably created by a class initializer and is reachable from a static field.
You can request class initialization at image runtime by using the option --initialize-at-run-time=<class-name>.
Or you can write your own initialization methods and call them explicitly from your main entry point.

@shingjo
Copy link
Contributor

shingjo commented Jul 8, 2022

With graal-vm: 22.1.0, you need to the use the 0.14.1 version of GCP native-image-support.

@sdelamo
Copy link
Contributor

sdelamo commented Aug 3, 2023

I upgraded the sample application to Micronaut Framework 4 .

io.micronaut.gcp:micronaut-gcp-tracing causes the following error:

Error: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of ch.qos.logback.core.status.InfoStatus are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=ch.qos.logback.core.status.InfoStatus.
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception

@msupic could you look into this?

@msupic
Copy link
Contributor

msupic commented Aug 3, 2023

@graemerocher - in the example created by @sdelamo, the dockerBuildNative task fails with the following error:

Error: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of ch.qos.logback.core.status.InfoStatus are allowed in the image heap as this class should be initialized at image runtime. Object has been initialized by the io.grpc.netty.shaded.io.netty.channel.AbstractChannel class initializer with a trace: 
     at ch.qos.logback.core.status.InfoStatus.<init>(InfoStatus.java:18)
    at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:85)
    at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:77)
    at ch.qos.logback.classic.spi.LogbackServiceProvider.initializeLoggerContext(LogbackServiceProvider.java:52)
    at ch.qos.logback.classic.spi.LogbackServiceProvider.initialize(LogbackServiceProvider.java:41)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:183)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:170)
    at org.slf4j.LoggerFactory.getProvider(LoggerFactory.java:455)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:441)
    at io.grpc.netty.shaded.io.netty.util.internal.logging.Slf4JLoggerFactory.<init>(Slf4JLoggerFactory.java:42)

The error happens because micronaut-gcp-tracing has dependency on io.grpc:grpc-netty-shaded. In the shared metadata repository there is no metadata for grpc-netty-shaded that would override metadata from grpc-netty-shaded library like there is for io.netty libs. So to fix the issue, I guess we need to add metadata for io.grpc:grpc-netty-shaded that would override the library metadata. @graemerocher - your thoughts?

@graemerocher
Copy link
Contributor

I raised the topic of shading of netty a while back with Vojin, really the metadata is the same as for Netty so it is duplicated work every time netty is shaded

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relates-to: graal type: bug Something isn't working
Projects
No open projects
Status: No status
Development

No branches or pull requests

7 participants