micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.06k stars 1.06k forks source link

Regression when upgrading to 3.1.4 : can't build picocli native image on windows #6595

Closed twobeeb closed 1 year ago

twobeeb commented 2 years ago

Expected Behavior

I'm using native image to compile a Micronaut Picocli CLI for windows and linux

Following Upgrade :

Linux build is successful Windows build is failed

Actual Behaviour

This github actions shows the failure with micronaut 3.1.4 and graalvm 21.3.0 https://github.com/michelin/ns4kafka/actions/runs/1509108289

Successful linux and windows build from a previous build before migrating to Micronaut 3.1.4 https://github.com/michelin/ns4kafka/actions/runs/1491868428

The error:

> Task :cli:nativeImage
[kafkactl-1.2.3-SNAPSHOT:2720]    classlist:   8,324.73 ms,  0.96 GB
[kafkactl-1.2.3-SNAPSHOT:2720]        (cap):  15,932.31 ms,  0.96 GB
[kafkactl-1.2.3-SNAPSHOT:2720]        setup:  19,482.44 ms,  0.96 GB
[kafkactl-1.2.3-SNAPSHOT:2720]     (clinit):   1,344.00 ms,  3.34 GB
[kafkactl-1.2.3-SNAPSHOT:2720]   (typeflow):  26,308.86 ms,  3.34 GB
[kafkactl-1.2.3-SNAPSHOT:2720]    (objects):  90,729.54 ms,  3.34 GB
[kafkactl-1.2.3-SNAPSHOT:2720]   (features):  15,271.58 ms,  3.34 GB
[kafkactl-1.2.3-SNAPSHOT:2720]     analysis: 138,586.75 ms,  3.34 GB
[kafkactl-1.2.3-SNAPSHOT:2720]     universe:   8,968.61 ms,  3.30 GB
[kafkactl-1.2.3-SNAPSHOT:2720]      (parse):   8,313.56 ms,  3.31 GB
[kafkactl-1.2.3-SNAPSHOT:2720]     (inline):  20,248.14 ms,  3.23 GB
[kafkactl-1.2.3-SNAPSHOT:2720]    (compile):  73,092.83 ms,  3.10 GB
[kafkactl-1.2.3-SNAPSHOT:2720]      compile: 105,749.87 ms,  3.10 GB
[kafkactl-1.2.3-SNAPSHOT:2720]        image:   6,051.36 ms,  3.14 GB
[kafkactl-1.2.3-SNAPSHOT:2720]        write:   2,305.31 ms,  3.14 GB
[kafkactl-1.2.3-SNAPSHOT:2720]      [total]: 289,948.54 ms,  3.14 GB
# Printing build artifacts to: D:\a\ns4kafka\ns4kafka\cli\build\native-image\kafkactl-1.2.3-SNAPSHOT.build_artifacts.txt
Fatal error:com.oracle.svm.core.util.VMError$HostedError: should not reach here
    at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:64)
    at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLL(JNIRegistrationSupport.java:256)
    at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLLs(JNIRegistrationSupport.java:230)
    at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.afterImageWrite(JNIRegistrationSupport.java:175)
    at com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$8(NativeImageGenerator.java:663)
    at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:73)
    at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:663)
    at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:488)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:403)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:569)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:122)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:599)
Error: Image build request failed with exit status 1

Steps To Reproduce

No response

Environment Information

github actions are configured with latest windows and ubuntu images I'm using graalvm jdk 11 everywhere

Example Application

https://github.com/michelin/ns4kafka (original project) https://github.com/twobeeb/demo (simplified version)

Version

3.1.4

twobeeb commented 2 years ago

I came to understand that the error in 21.1.0 is unrelated micronaut-projects/micronaut-core#5655

So I focused to graalvm 21.3.0. I created a new project from micronaut launch in order to use the latest version of Micronaut (3.2.0) and micronaut plugin (3.0.0). https://github.com/twobeeb/demo/actions Each new commit tries to reduce the complexity of the project but no luck so far...

Thanks for your help

twobeeb commented 2 years ago

Ok so I found 2 issues that makes windows build fail:

Check the associated github actions to understand how I came to that conclusion. https://github.com/twobeeb/demo/actions As a reminder, the linux build was always successful for every workflow run

graemerocher commented 2 years ago

@twobeeb so you are saying it works on Linux but fails only on Windows?

twobeeb commented 2 years ago

@graemerocher precisely. Each commit on this project https://github.com/twobeeb/demo/ triggers the linux and windows workflows. As you can see, I managed to isolate 2 distinct elements that produce the same error :

In every failed workflow, the linux build was successful

twobeeb commented 2 years ago

I updated to micronaut plugin 3.0.1 this afternoon, and I was happy to see that the build is now successful.

Unfortunately, now every injected Singleton is returning NullPointerException in native-image builds on windows

Windows :

PS C:\Users\F297755\.kafkactl> .\kafkactl.exe
java.lang.NullPointerException
        at com.michelin.ns4kafka.cli.KafkactlCommand.call(KafkactlCommand.java:63)
        at com.michelin.ns4kafka.cli.KafkactlCommand.call(KafkactlCommand.java:13)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at io.micronaut.configuration.picocli.PicocliRunner.execute(PicocliRunner.java:202)
        at io.micronaut.configuration.picocli.PicocliRunner.execute(PicocliRunner.java:179)
        at com.michelin.ns4kafka.cli.KafkactlCommand.main(KafkactlCommand.java:56)

Linux build:

julien@Julien-PC:$ ./kafkactl
v0.1
Usage: kafkactl [-hvV] [-n=<optionalNamespace>] [COMMAND]
  -h, --help      Show this help message and exit.
  -n, --namespace=<optionalNamespace>
                  Override namespace defined in config or yaml resource
  -v, --verbose   ...
  -V, --version   Print version information and exit.
Commands:
  apply           Create or update a resource
  get             Get resources by resource type for the current namespace
  delete          Delete a resource
  api-resources   Print the supported API resources on the server
  diff            Get differences between the new resources and the old resource
  reset-offsets   Reset Consumer Group offsets
  delete-records  Deletes all records within a topic
  import          Import resources already present on the Kafka Cluster in
                    ns4kafka
  connectors      Interact with connectors (Pause/Resume/Restart)
twobeeb commented 2 years ago

This NullPointerException behavior is reproduced on the simplest possible CLI project : https://github.com/twobeeb/demo-http-cli

PS C:\Users\F297755\.kafkactl> .\kafkactl.exe> .\demo-http-cli.exe
←[36m22:32:12.449←[0;39m ←[1;30m[main]←[0;39m ←[34mINFO ←[0;39m ←[35mi.m.context.env.DefaultEnvironment←[0;39m - Established active environments: [cli]
java.lang.NullPointerException
        at com.example.DemoHttpCliCommand.run(DemoHttpCliCommand.java:27)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1939)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at io.micronaut.configuration.picocli.PicocliRunner.run(PicocliRunner.java:137)
        at io.micronaut.configuration.picocli.PicocliRunner.run(PicocliRunner.java:114)
        at com.example.DemoHttpCliCommand.main(DemoHttpCliCommand.java:22)
graemerocher commented 2 years ago

@twobeeb going to investigate

melix commented 2 years ago

Can you compare the contents of the build/native/generated/generateResourcesConfigFile/resource-config.json file on Linux and Windows?

graemerocher commented 2 years ago

@twobeeb can you confirm whether the NPE only happens on Windows?

twobeeb commented 2 years ago

@graemerocher Confirmed. The issue is only on windows build (this error is network error, This VM doesn't have internet access, bit it clearly "worked")

[foundation@carsfkc01 ~]$ ./demo-http-cli 
11:04:05.773 [main] INFO  i.m.context.env.DefaultEnvironment - Established active environments: [cli]
11:04:16.806 [main] ERROR i.m.r.intercept.RecoveryInterceptor - Type [com.example.GithubClient$Intercepted] executed with error: Read Timeout
io.micronaut.http.client.exceptions.ReadTimeoutException: Read Timeout
io.micronaut.http.client.exceptions.ReadTimeoutException: Read Timeout

@melix my demo project contains the github action with the artifacts containing what you need : https://github.com/twobeeb/demo-http-cli/actions/runs/1528085284

Windows and Linux both have the following resource-config.json

{
  "resources" : {
    "includes" : [ ],
    "excludes" : [ ]
  },
  "bundles" : [ ]
}
twobeeb commented 2 years ago

Hi @graemerocher @melix Just FYI, I reverted my project to micronaut 2.5.x. I discovered then that I can't build on windows with graalvm later than 20.3.x https://github.com/michelin/ns4kafka/blob/master/.github/workflows/on_push_master.yml linux build is fine on graalvm 21.1.0 I don't know if this information could be any help...

Nokorbis commented 2 years ago

Hello, I'm having the same issue (NullPointerException on a injected singleton) with a project generated this week using the launcher

loicgreffier commented 2 years ago

Hello, I faced the same issue: NullPointerException on an injected bean when running a Command Line App as Windows native executable.

Just instantiated a brand new project with:

However, it seems working when the project is built with Maven instead of Gradle.

Working: https://github.com/loicgreffier/micronaut-picocli-maven Not working: https://github.com/twobeeb/micronaut-issue-6595

The only difference is the build tool so the issue seems coming from the build with Gradle. Can anybody confirm ?

graemerocher commented 2 years ago

@alvarosanchez @melix could you investigate this for Windows for both Maven and Gradle

altro3 commented 2 years ago

Hi! I confirm. Same problem.

Micronaut 3.3.3, Command Line Application GraalVM 22.0.0.2 Windows 10 Visual Studio Build Tools 2022 Gradle 7.4

loicgreffier commented 1 year ago

I tested this issue again with:

There is no more injection issue for me, I can run both of my native Linux/Windows images as expected