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

use correct vfs path 'contents' #5732

Closed
wants to merge 1 commit into from
Closed

Conversation

cherni78
Copy link

Since Wildfly 31.0.0 we encountered the following problem:

ERROR [org.drools.compiler.kie.builder.impl.ClasspathKieProject] (EJB async-pool - 3) [Usr#] Unable to build index of kmodule.xml url=vfs:/.../wildfly-31.0.0.Final/standalone/deployments/.../META-INF/kmodule.xml
Unable to get all ZipFile entries: ...\wildfly-31.0.0.Final\standalone\tmp\vfs\deployment\deploymentedb670f3fadfd5b0\...\content



Caused by: java.lang.RuntimeException: Cannot find a default KieSession
	at deployment.BisonProcess.ear//org.drools.compiler.kie.builder.impl.KieContainerImpl.findKieSessionModel(KieContainerImpl.java:557)
	at deployment.BisonProcess.ear//org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:600)
	at deployment.BisonProcess.ear//org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:530)
	at deployment.BisonProcess.ear//org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:513)

Seems that the problem comes from the typo in the fixed typed vfs lookup path.
After changing it to 'contents' it works well!

@mariofusco
Copy link
Contributor

Fixed by 72c1d6b

@mariofusco mariofusco closed this Feb 26, 2024
@cherni78
Copy link
Author

cherni78 commented Feb 26, 2024

I think it's not fixed.
Because here is still the wrong path with 'content' instead of 'contents'.

@reinhapa
Copy link

Fixed by 72c1d6b

@mariofusco we found that change in our currently used drools version 9.44.0, that does not work as intended and produces the exact stack as described in this issue...

@mariofusco
Copy link
Contributor

This is not a simple typo (it worked with old wildfly) but the effect of a recent change in wildfly/eap as it has been reported here https://issues.redhat.com/browse/DROOLS-7608

@cherni78 @reinhapa I'd appreciate it if you could give a try to your reproducers using the commits that I linked and if it doesn't work I will investigate again the problem. But at the moment simply adding an 's' doesn't seem the right solution and however if I do so I will also break compatibility with wildfly versions < 31.0

@cherni78
Copy link
Author

cherni78 commented Feb 28, 2024

After a few more analyses @reinhapa and I found the problem with Wildfly 31.0.0.
It seems to be a ClassLoader-Problem. It happens in the method ImmutableRuleCompilationPhase.compileRulesLevel

The ContextClassLoader used within the ForkJoinPoolTask is not the same as within the compileRulesLevel method.
When passing the ClassLoader into the lambda everything works as expected.

The following patch worked:

diff --git a/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/ImmutableRuleCompilationPhase.java b/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/ImmutableRuleCompilationPhase.java
index ac94c80e78..9a8055b9ee 100644
--- a/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/ImmutableRuleCompilationPhase.java
+++ b/drools-compiler/src/main/java/org/drools/compiler/builder/impl/processors/ImmutableRuleCompilationPhase.java
@@ -269,18 +269,25 @@ public class ImmutableRuleCompilationPhase extends AbstractPackageCompilationPha
         if (parallelRulesBuild) {
             Map<String, RuleBuildContext> ruleCxts = new ConcurrentHashMap<>();
             try {
+                final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
                 KnowledgeBuilderImpl.ForkJoinPoolHolder.COMPILER_POOL.submit(() ->
                         rules.stream().parallel()
                                 .filter(ruleDescr -> filterAccepts(ResourceChange.Type.RULE, ruleDescr.getNamespace(), ruleDescr.getName()))
                                 .forEach(ruleDescr -> {
-                                    initRuleDescr(packageDescr, pkgRegistry, ruleDescr);
-                                    RuleBuildContext context = buildRuleBuilderContext(pkgRegistry, ruleDescr);
-                                    ruleCxts.put(ruleDescr.getName(), context);
-                                    List<? extends KnowledgeBuilderResult> results = addRule(context);
-                                    if (!results.isEmpty()) {
-                                        synchronized (this.results) {
-                                            this.results.addAll(results);
-                                        }
+                                    final ClassLoader savedCurrentClassLoader = Thread.currentThread().getContextClassLoader();
+                                    try {
+                                      Thread.currentThread().setContextClassLoader(contextClassLoader);
+                                      initRuleDescr(packageDescr, pkgRegistry, ruleDescr);
+                                      RuleBuildContext context = buildRuleBuilderContext(pkgRegistry, ruleDescr);
+                                      ruleCxts.put(ruleDescr.getName(), context);
+                                      List<? extends KnowledgeBuilderResult> results = addRule(context);
+                                      if (!results.isEmpty()) {
+                                          synchronized (this.results) {
+                                              this.results.addAll(results);
+                                          }
+                                      }
+                                    } finally {
+                                      Thread.currentThread().setContextClassLoader(savedCurrentClassLoader);
                                     }
                                 })
                 ).get();

@reinhapa
Copy link

reinhapa commented Mar 4, 2024

@mariofusco seems that the current fix does still have some glitch when using a fork join pool.

@mariofusco
Copy link
Contributor

@cherni78 @reinhapa I'm investigating this problem again, but still not able to reproduce it. Can you please provide a simple example reproducing thus issue, so we will be sure of being on the same page? Thanks.

@mariofusco mariofusco reopened this Mar 11, 2024
@mariofusco
Copy link
Contributor

I created a sample project using our current main branch, tested under WildFly Full 31.0.1.Final and it seems to work fine for me. In particular it is able to correctly retrieve the KieProject inside the classpath as reported by the log.

14:08:10,832 INFO  [org.drools.compiler.kie.builder.impl.ClasspathKieProject] (default task-1) Found kmodule: vfs:/content/rest-endpoint.war/WEB-INF/lib/drools-project-1.0-SNAPSHOT.jar/META-INF/kmodule.xml
14:08:10,834 INFO  [org.drools.compiler.kie.builder.impl.ClasspathKieProject] (default task-1) Virtual file physical path = /home/mario/software/wildfly-31.0.1.Final/standalone/tmp/vfs/temp/tempd4b311ff42b8e2fe/content-c070abcdbe655535/WEB-INF/lib/drools-project-1.0-SNAPSHOT.jar

Please modify the sample project that I'm providing (or feel free to send your reproducer) in case you still think that there is a problem.

@mariofusco mariofusco closed this Mar 11, 2024
@reinhapa
Copy link

I created a sample project using our current main branch, tested under WildFly Full 31.0.1.Final and it seems to work fine for me. In particular it is able to correctly retrieve the KieProject inside the classpath as reported by the log.

@mariofusco We will give it a try and come back to you...

@mareknovotny
Copy link
Contributor

@reinhapa @cherni78 can you guys create then an issue here https://github.com/apache/incubator-kie-drools/issues to properly track it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants