apache / camel-quarkus

Apache Camel Quarkus
https://camel.apache.org
Apache License 2.0
256 stars 189 forks source link

Camel Quarkus + Azure Cosmos DB in Native Mode Issue Detected an instance of Random/SplittableRandom class #3891

Open DouglasGo8 opened 2 years ago

DouglasGo8 commented 2 years ago

Hi Guys, I'm working in a project that needs use Azure DB Cosmos using Quarkus with GraalVM, bellow my stack

OS - MacOS Monterrey over M1 Max Machine arc64 (the same problem happens using Linux Containers)

To reproduce the issue

Maven Dependencies

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <compiler-plugin.version>3.8.1</compiler-plugin.version>
    <maven.compiler.parameters>true</maven.compiler.parameters>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
    <quarkus.platform.version>2.10.1.Final</quarkus.platform.version>
    <surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
</properties>
<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>${quarkus.platform.artifact-id}</artifactId>
        <version>${quarkus.platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>com.azure</groupId>
        <artifactId>azure-sdk-bom</artifactId>
        <version>1.2.2</version>
        <type>pom</type>
        <scope>import</scope>
        <!--
        <exclusions>
          <exclusion>
            <groupId>com.azure</groupId>
            <artifactId>azure-core-http-netty</artifactId>
          </exclusion>
        </exclusions>
        -->
      </dependency>
    </dependencies>
  </dependencyManagement>
<dependencies>
    <!-- Azure SDK -->
    <!--
    <dependency>
      <groupId>com.azure</groupId>
      <artifactId>azure-cosmos</artifactId>
      <exclusions>
        <exclusion>
          <groupId>com.azure</groupId>
          <artifactId>azure-core-http-netty</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    -->
    <dependency>
      <groupId>io.netty</groupId>
      <artifactId>netty-transport-native-epoll</artifactId>
    </dependency>
    <!-- Thanks for using https://jar-download.com -->
    <!--
    <dependency>
      <groupId>com.azure</groupId>
      <artifactId>azure-storage-blob</artifactId>
      <exclusions>
        <exclusion>
          <groupId>com.azure</groupId>
          <artifactId>azure-core-http-netty</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    -->
    <!-- Quarkus SDK -->
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-funqy-knative-events</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-azure-cosmosdb</artifactId>
      <version>2.9.0</version>
    </dependency>
    <!-- Misc -->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.24</version>
    </dependency>
    <!--  Test -->
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-junit5</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-arc</artifactId>
    </dependency>
  </dependencies>

Command to try to generate the native bin

Only Mac OS Binary

mvn clean -DskipTests package -Pnative -Dquarkus.native.native-image-xmx=4g

Only Linux arch64 Binary

./mvnw -DskipTests clean compile package -Pnative -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true -Dquarkus.native.builder-image=graalbasev17 -Dquarkus.native.native-image-xmx=5g

The Error Output

[1/7] Initializing...                                                                                    (7.9s @ 0.27GB)
 Version info: 'GraalVM 22.1.0 Java 17 CE'
 C compiler: gcc (redhat, aarch64, 8.5.0)
 Garbage collector: Serial GC
 3 user-provided feature(s)
  - io.quarkus.runner.AutoFeature
  - io.quarkus.runtime.graal.DisableLoggingAutoFeature
  - io.quarkus.runtime.graal.ResourcesFeature
13:29:41,920 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting PartitionKeyAccessor...
13:29:42,059 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosClientBuilderAccessor...
13:29:42,064 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting DirectConnectionConfigAccessor...
13:29:42,182 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosBatchAccessor...
13:29:42,183 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosBatchOperationResultAccessor...
13:29:42,183 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosBatchRequestOptionsAccessor...
13:29:42,184 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosBatchResponseAccessor...
13:29:42,185 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosBulkExecutionOptionsAccessor...
13:29:42,185 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosBulkExecutionThresholdsStateAccessor...
13:29:42,186 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosBulkItemResponseAccessor...
13:29:42,186 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosChangeFeedRequestOptionsAccessor...
13:29:42,187 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosContainerPropertiesAccessor...
13:29:42,187 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosItemRequestOptionsAccessor...
13:29:42,188 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosItemResponseBuilderAccessor...
13:29:42,188 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosPatchOperationsAccessor...
13:29:42,189 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosQueryRequestOptionsAccessor...
13:29:42,189 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting FeedResponseAccessor...
13:29:42,233 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosClientAccessor...
13:29:42,234 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosAsyncClientEncryptionKeyAccessor...
13:29:42,236 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosAsyncContainerAccessor...
13:29:42,236 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosAsyncDatabaseAccessor...
13:29:42,250 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosPageFluxAccessor...
13:29:42,265 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosDiagnosticsAccessor...
13:29:42,266 INFO  [com.azu.cos.imp.ImplementationBridgeHelpers] Setting CosmosExceptionAccessor...
13:29:44,573 INFO  [com.azu.cos.imp.dir.RntbdTransportClient] Using default Direct TCP options: azure.cosmos.directTcp.defaultOptions
[2/7] Performing analysis...  []                                                                         (8.3s @ 0.94GB)
   8,997 (92.61%) of  9,715 classes reachable
  11,940 (59.46%) of 20,081 fields reachable
  36,329 (78.61%) of 46,214 methods reachable
     572 classes,     0 fields, and     0 methods registered for reflection
Fatal error: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. 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.
    at com.oracle.graal.pointsto.util.AnalysisFuture.setException(AnalysisFuture.java:49)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:269)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$postTask$9(ImageHeapScanner.java:611)
    at com.oracle.graal.pointsto.util.CompletionExecutor.executeCommand(CompletionExecutor.java:193)
    at com.oracle.graal.pointsto.util.CompletionExecutor.lambda$executeService$0(CompletionExecutor.java:177)
------------------------------------------------------------------------------------------------------------------------
    at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected an instance of Random/SplittableRandom class in the image heap. Instances created during image generation have cached seed values and don't behave as expected.  To see how this object got instantiated use --trace-object-instantiation=java.util.Random. 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.

Addional load class initialization info over properties file

quarkus.native.additional-build-args=--allow-incomplete-classpath,--initialize-at-run-time=org.acme.RandomWrapper\\,\
  io.netty.channel.epoll.Epoll\\,\
  io.netty.channel.epoll.EpollEventLoop\\,\
  io.netty.channel.epoll.Native\\,\
  io.netty.channel.epoll.EpollEventArray\\,\
  io.netty.channel.DefaultFileRegion\\,\
  io.netty.channel.unix.Errors\\,\
  org.apache.http.impl.auth.NTLMEngineImpl\\,\
  io.grpc.netty.shaded.io.netty.util.internal.logging.Log4JLogger\\,\
  io.netty.util.internal.logging.Log4JLogger
ppalaga commented 2 years ago

camel-quarkus-azure-cosmosdb is not supported in native mode yet - see https://camel.apache.org/camel-quarkus/latest/reference/index.html and https://github.com/apache/camel-quarkus/issues/2648

A contribution towards supporting it would be highly welcome. Please check our Contributor guide or feel free to ask specific questions if you are interested.

DouglasGo8 commented 2 years ago

Thanks for quick reply @ppalaga