apache / camel-quarkus

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

Native build fails when using both camel-quarkus-activemq and quarkus-jdbc-oracle #3980

Closed lorenzobenvenuti closed 1 year ago

lorenzobenvenuti commented 2 years ago

Hi,

I noticed that native build fails if a project is using both camel-quarkus-activemq and quarkus-jdbc-oracle. The issue looks similar to this:

The error I see is non-deterministic (probably the build is multi-threaded and Graalvm returns the first error?): sometimes it returns

Error: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  To see how this object got instantiated use --trace-object-instantiation=com.sun.jmx.mbeanserver.JmxMBeanServer. 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.
com.oracle.graal.pointsto.util.AnalysisError: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  To see how this object got instantiated use --trace-object-instantiation=com.sun.jmx.mbeanserver.JmxMBeanServer. 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.AnalysisError.shouldNotReachHere(AnalysisError.java:172)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:66)
    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: java.util.concurrent.ExecutionException: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  To see how this object got instantiated use --trace-object-instantiation=com.sun.jmx.mbeanserver.JmxMBeanServer. 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 java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:64)
    ... 9 more
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  To see how this object got instantiated use --trace-object-instantiation=com.sun.jmx.mbeanserver.JmxMBeanServer. 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.svm.hosted.image.DisallowedImageHeapObjectFeature.error(DisallowedImageHeapObjectFeature.java:173)
    at com.oracle.svm.hosted.image.DisallowedImageHeapObjectFeature.checkDisallowedMBeanObjects(DisallowedImageHeapObjectFeature.java:156)
    at com.oracle.svm.hosted.image.DisallowedImageHeapObjectFeature.replacer(DisallowedImageHeapObjectFeature.java:119)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.replaceObject(AnalysisUniverse.java:582)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.maybeReplace(ImageHeapScanner.java:296)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.createImageHeapObject(ImageHeapScanner.java:216)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$getOrCreateConstantReachableTask$2(ImageHeapScanner.java:195)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.getOrCreateConstantReachableTask(ImageHeapScanner.java:207)
    at com.oracle.svm.hosted.heap.SVMImageHeapScanner.getOrCreateConstantReachableTask(SVMImageHeapScanner.java:94)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.markConstantReachable(ImageHeapScanner.java:171)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.onArrayElementReachable(ImageHeapScanner.java:369)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.createImageHeapObject(ImageHeapScanner.java:246)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$getOrCreateConstantReachableTask$2(ImageHeapScanner.java:195)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.getOrCreateConstantReachableTask(ImageHeapScanner.java:207)
    at com.oracle.svm.hosted.heap.SVMImageHeapScanner.getOrCreateConstantReachableTask(SVMImageHeapScanner.java:94)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.markConstantReachable(ImageHeapScanner.java:171)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.onFieldValueReachable(ImageHeapScanner.java:333)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$createImageHeapObject$3(ImageHeapScanner.java:272)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)------------------------------------------------------------------------------------------------------------------------
                        3.2s (7.3% of total time) in 20 GCs | Peak RSS: 4.28GB | CPU load: 6.00
========================================================================================================================
Failed generating 'oracle-native-image-error-1.0.0-SNAPSHOT-runner' after 43.3s.

    ... 9 more
Error: java.util.concurrent.ExecutionException: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  To see how this object got instantiated use --trace-object-instantiation=com.sun.jmx.mbeanserver.JmxMBeanServer. 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.
com.oracle.graal.pointsto.util.AnalysisError: java.util.concurrent.ExecutionException: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  To see how this object got instantiated use --trace-object-instantiation=com.sun.jmx.mbeanserver.JmxMBeanServer. 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.AnalysisError.shouldNotReachHere(AnalysisError.java:172)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:66)
    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: java.util.concurrent.ExecutionException: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  To see how this object got instantiated use --trace-object-instantiation=com.sun.jmx.mbeanserver.JmxMBeanServer. 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 java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:64)
    ... 9 more
Caused by: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  To see how this object got instantiated use --trace-object-instantiation=com.sun.jmx.mbeanserver.JmxMBeanServer. 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.getOrCreateConstantReachableTask(ImageHeapScanner.java:207)
    at com.oracle.svm.hosted.heap.SVMImageHeapScanner.getOrCreateConstantReachableTask(SVMImageHeapScanner.java:94)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.markConstantReachable(ImageHeapScanner.java:171)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.onArrayElementReachable(ImageHeapScanner.java:369)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.createImageHeapObject(ImageHeapScanner.java:246)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$getOrCreateConstantReachableTask$2(ImageHeapScanner.java:195)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.getOrCreateConstantReachableTask(ImageHeapScanner.java:207)
    at com.oracle.svm.hosted.heap.SVMImageHeapScanner.getOrCreateConstantReachableTask(SVMImageHeapScanner.java:94)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.markConstantReachable(ImageHeapScanner.java:171)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.onFieldValueReachable(ImageHeapScanner.java:333)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$createImageHeapObject$3(ImageHeapScanner.java:272)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.oracle.graal.pointsto.util.AnalysisFuture.ensureDone(AnalysisFuture.java:63)
    ... 9 more
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Detected a MBean server in the image heap. This is currently not supported, but could be changed in the future. Management beans are registered in many global caches that would need to be cleared and properly re-built at image build time. Class of disallowed object: com.sun.jmx.mbeanserver.JmxMBeanServer  To see how this object got instantiated use --trace-object-instantiation=com.sun.jmx.mbeanserver.JmxMBeanServer. 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.svm.hosted.image.DisallowedImageHeapObjectFeature.error(DisallowedImageHeapObjectFeature.java:173)
    at com.oracle.svm.hosted.image.DisallowedImageHeapObjectFeature.checkDisallowedMBeanObjects(DisallowedImageHeapObjectFeature.java:156)
    at com.oracle.svm.hosted.image.DisallowedImageHeapObjectFeature.replacer(DisallowedImageHeapObjectFeature.java:119)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.replaceObject(AnalysisUniverse.java:582)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.maybeReplace(ImageHeapScanner.java:296)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.createImageHeapObject(ImageHeapScanner.java:216)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$getOrCreateConstantReachableTask$2(ImageHeapScanner.java:195)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    ... 25 more
Error: Image build request failed with exit status 1

while sometimes it returns

Fatal error: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: type is not available in this platform: org.graalvm.compiler.hotspot.management.AggregatedMemoryPoolBean
    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: type is not available in this platform: org.graalvm.compiler.hotspot.management.AggregatedMemoryPoolBean
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.createType(AnalysisUniverse.java:220)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookupAllowUnresolved(AnalysisUniverse.java:211)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:188)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.lookup(AnalysisUniverse.java:74)
    at com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess$1.apply(UniverseMetaAccess.java:52)
    at com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess$1.apply(UniverseMetaAccess.java:49)
    at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1740)
    at com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess.lookupJavaType(UniverseMetaAccess.java:84)
    at com.oracle.graal.pointsto.meta.AnalysisMetaAccess.lookupJavaType(AnalysisMetaAccess.java:52)
    at com.oracle.svm.hosted.ameta.HostedDynamicHubFeature.replace(HostedDynamicHubFeature.java:52)
    at com.oracle.graal.pointsto.meta.AnalysisUniverse.replaceObject(AnalysisUniverse.java:582)
    at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.replaceObject(AnalysisConstantReflectionProvider.java:257)
    at com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider.interceptValue(AnalysisConstantReflectionProvider.java:228)
    at com.oracle.svm.hosted.heap.SVMImageHeapScanner.transformFieldValue(SVMImageHeapScanner.java:126)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.onFieldValueReachable(ImageHeapScanner.java:331)
    at com.oracle.graal.pointsto.heap.ImageHeapScanner.lambda$createImageHeapObject$3(ImageHeapScanner.java:272)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    ... 10 more------------------------------------------------------------------------------------------------------------------------

The issue happens with Quarkus 2.11.1.Final, I didn't try with other versions.

I've reproduced the bug here: https://github.com/lorenzobenvenuti/quarkus-amq-oracle-native-image-error mvn package -Pnative will fail for main; if we use a different component for the consumer (camel-file branch is using camel-quarkus-file) then the build is successful.

Thanks,

lorenzo

jamesnetherton commented 2 years ago

As a workaround try: --initialize-at-run-time=oracle.jdbc.driver.OracleDriver.

lorenzobenvenuti commented 2 years ago

It did the trick, thank you very much! I tried oracle.jdbc.datasource.impl.OracleDataSource efore but I didn't think to try with the driver class too. Thanks!

ppalaga commented 2 years ago

@Sanne can you see a better mitigation by any chance?

Sanne commented 2 years ago

Interesting, thanks for pinging me.

The workaround seems to fly directly against our expectations, so it might have problematic side effects on other components:

https://github.com/quarkusio/quarkus/blob/23f43c3d3be6f479f86f697888856a8c65d8136d/extensions/jdbc/jdbc-oracle/deployment/src/main/java/io/quarkus/jdbc/oracle/deployment/OracleMetadataOverrides.java#L72-L76

The error seems to suggest the MBeans have been initialized; we make sure the MBean registration code is disabled:

But such substitutions only apply to after-compilation to native. I suspect what is happening is that some other component is aggressively initializing the class - I guess triggered by that aactivemq extension? I'll try to debug the reproducer, thanks!

turing85 commented 1 year ago

We are seeing a similar issue, but we are using camel-quarkus-jms. Could this have the same cause?

zhfeng commented 1 year ago

@turing85 Do you have any re-producer with camel-quarkus-jms?

turing85 commented 1 year ago

@zhfeng none that I can share easily. Haven't check yet if I can reproduce it with a MRE. This week is packed, so I will not be able to create the MRE. Maybe on the weekend or at the beginning of next week.

zhfeng commented 1 year ago

@turing85 no problem. I tried with the orignal reproducer of this issue above. And it only failed with camel-quarkus-activemq but not camel-quarkus-jms.

turing85 commented 1 year ago

@zhfeng You could try to activate XA on the connection. I know that my use-case uses XA.

zhfeng commented 1 year ago

Thanks @turing85 - now I can reproduce the issue by using quarkus-artemis and quarkus-pooled-jms. And if I removes quarkus-pooled-jms, it works again. I will take a look.

zhfeng commented 1 year ago

Hmm, it is intersting that both of them camel-quarkus-activemq and quarkus-pooled-jms depend on org.apache.commons:commons-pool2 which seems that the poolConfig has JmxEnable property.

zhfeng commented 1 year ago

OK, then add a subsition to disable the JMX register and unresiger in commons-pool2 could fix the issue.

zhfeng commented 1 year ago

@lorenzobenvenuti can you review https://github.com/apache/camel-quarkus/pull/4287 ? I tried with your original re-producer and it works locally with this fix.