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 build fails with Micronaut 4.2.1 #464

Open
msixta opened this issue Dec 14, 2023 · 4 comments
Open

Native image build fails with Micronaut 4.2.1 #464

msixta opened this issue Dec 14, 2023 · 4 comments

Comments

@msixta
Copy link

msixta commented Dec 14, 2023

Expected Behavior

Building native-image of Micronaut 4.2.1 with tracing-opentelemetry-jaeger dependency succeeds.

Actual Behaviour

Builds fails with:

[1/8] Initializing... (4.9s @ 0.33GB)
Java version: 17.0.7+8-LTS, vendor version: Oracle GraalVM 17.0.7+8.1
Graal compiler: optimization level: b, target machine: x86-64-v3, PGO: off
C compiler: gcc (linux, x86_64, 9.4.0)
Garbage collector: G1 GC (max heap size: 25.0% of RAM)
2 user-specific feature(s)

  • io.micronaut.cache.caffeine.graal.CaffeineFeature
  • io.micronaut.core.io.service.ServiceLoaderFeature
    [2/8] Performing analysis... [*] (37.7s @ 3.03GB)
    20,125 (90.34%) of 22,278 types reachable
    30,898 (62.72%) of 49,262 fields reachable
    111,996 (65.06%) of 172,153 methods reachable
    6,980 types, 602 fields, and 5,535 methods registered for reflection
    5 native libraries: dl, g1gc-cr, m, pthread, stdc++

Error: Classes that should be initialized at run time got initialized during image building:
kotlin.coroutines.intrinsics.CoroutineSingletons was unintentionally initialized at build time. To see why kotlin.coroutines.intrinsics.CoroutineSingletons got initialized use --trace-class-initialization=kotlin.coroutines.intrinsics.CoroutineSingletons
To see how the classes got initialized, use --trace-class-initialization=kotlin.coroutines.intrinsics.CoroutineSingletons
Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception

Works with Micronaut 4.1.6, discussed on Discord "Micronaut Framework 4.2.0 updates to Kotlin 1.9.2 so it appears something broke."

https://discord.com/channels/1121511613250412714/1182711987310960670

Steps To Reproduce

  1. Create micronaut service with graalvm / tracing-opentelemetry-jaeger via Launch
  2. run /mvnw -Dpackaging=native-image package -P graalvm

Environment Information

OS: Ubuntu
Java version: 17.0.7+8-LTS, vendor version: Oracle GraalVM 17.0.7+8.1

Example Application

Here is the sample project https://github.com/msixta/native-image

Version

4.2.1

@saw303
Copy link

saw303 commented Dec 15, 2023

Hi,

I'm not sure that this behaviour is micronaut-tracing related. I experience the same with Micronaut 4.2.1 w/o any dependency to micronaut-tracing. My guess is that this must be something general in combination with Kotlin.

When adding `` I get this additional output:

57.03 Error: Classes that should be initialized at run time got initialized during image building:
57.03  kotlin.coroutines.intrinsics.CoroutineSingletons was unintentionally initialized at build time. io.micronaut.core.util.KotlinUtils caused initialization of this class with the following trace: 
57.03   at kotlin.coroutines.intrinsics.CoroutineSingletons.<clinit>(Intrinsics.kt:64)
57.03   at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsKt.getCOROUTINE_SUSPENDED(Intrinsics.kt:57)
57.03   at io.micronaut.core.util.KotlinUtils.<clinit>(KotlinUtils.java:45)

my DockerfileNative looks like this

FROM ghcr.io/graalvm/native-image-community:17-ol9 AS graalvm
WORKDIR /home/app
COPY layers/libs /home/app/libs
COPY layers/classes /home/app/classes
COPY layers/resources /home/app/resources
COPY layers/application.jar /home/app/application.jar
RUN mkdir /home/app/config-dirs
RUN mkdir -p /home/app/config-dirs/generateResourcesConfigFile
RUN mkdir -p /home/app/config-dirs/io.netty/netty-common/4.1.80.Final
RUN mkdir -p /home/app/config-dirs/org.jetbrains.kotlin/kotlin-stdlib/1.7.10
RUN mkdir -p /home/app/config-dirs/org.jetbrains.kotlin/kotlin-reflect/1.7.10
RUN mkdir -p /home/app/config-dirs/ch.qos.logback/logback-classic/1.4.1
COPY config-dirs/generateResourcesConfigFile /home/app/config-dirs/generateResourcesConfigFile
COPY config-dirs/io.netty/netty-common/4.1.80.Final /home/app/config-dirs/io.netty/netty-common/4.1.80.Final
COPY config-dirs/org.jetbrains.kotlin/kotlin-stdlib/1.7.10 /home/app/config-dirs/org.jetbrains.kotlin/kotlin-stdlib/1.7.10
COPY config-dirs/org.jetbrains.kotlin/kotlin-reflect/1.7.10 /home/app/config-dirs/org.jetbrains.kotlin/kotlin-reflect/1.7.10
COPY config-dirs/ch.qos.logback/logback-classic/1.4.1 /home/app/config-dirs/ch.qos.logback/logback-classic/1.4.1
RUN native-image --trace-class-initialization=kotlin.coroutines.intrinsics.CoroutineSingletons --exclude-config .*/libs/netty-transport-4.1.101.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-buffer-4.1.101.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http-4.1.101.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-handler-4.1.101.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-common-4.1.101.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http2-4.1.101.Final.jar ^/META-INF/native-image/.* -cp /home/app/libs/*.jar:/home/app/resources:/home/app/application.jar --no-fallback -o application -H:ConfigurationFileDirectories=/home/app/config-dirs/generateResourcesConfigFile,/home/app/config-dirs/io.netty/netty-buffer/4.1.80.Final,/home/app/config-dirs/io.netty/netty-common/4.1.80.Final,/home/app/config-dirs/io.netty/netty-codec-http/4.1.80.Final,/home/app/config-dirs/io.netty/netty-transport/4.1.80.Final,/home/app/config-dirs/io.netty/netty-handler/4.1.80.Final,/home/app/config-dirs/io.netty/netty-codec-http2/4.1.80.Final,/home/app/config-dirs/org.jetbrains.kotlin/kotlin-stdlib/1.7.10,/home/app/config-dirs/org.jetbrains.kotlin/kotlin-reflect/1.7.10,/home/app/config-dirs/ch.qos.logback/logback-classic/1.4.1 ch.onstructive.gpr.Application
FROM ubuntu:23.10
EXPOSE 8080
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
HEALTHCHECK CMD curl -s localhost:8080/endpoints/health | grep '"status":"UP"'
RUN groupadd app && useradd -rm -d /home/app -s /bin/bash -g app -u 1001 app
USER app
COPY --from=graalvm /home/app/application /app/application
ENTRYPOINT ["/app/application"]

@graemerocher
Copy link
Contributor

something broke / changed in Kotlin 1.9, downgrading to 1.8 will fix it

@msixta
Copy link
Author

msixta commented Dec 15, 2023

I'm not sure that this behaviour is micronaut-tracing related. I experience the same with Micronaut 4.2.1 w/o any dependency to micronaut-tracing. My guess is that this must be something general in combination with Kotlin.

It compiles fine if I remove io.opentelemetry:opentelemetry-exporter-jaeger dependency. So yes it seems to be more general problem, but on the other hand it affects specifically micronaut-tracing with jaeger exporter

@graemerocher
Copy link
Contributor

it effects it because this exporter uses okhttp which moved from Java to Kotlin and now requires Kotlin standard lib which is what is broken it seems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: No status
Development

No branches or pull requests

4 participants