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

Infinity loop when build root project with multiple sub projects #29770

Closed
benstonezhang opened this issue Dec 9, 2022 · 7 comments
Closed
Labels
area/bootstrap kind/bug Something isn't working
Milestone

Comments

@benstonezhang
Copy link
Contributor

benstonezhang commented Dec 9, 2022

Describe the bug

To build a big project with multiple sub projects, we usually create them as below:

root project - (parent) -> base

root project have sub modules: base, base-quarkus, quarkus-example

base-quarkus - (parent) -> base

quarkus-example - (parent) -> base-quarkus

Quarkus release after 2.13.0 have this issue. In fact, this issue is introduced by commit a426f6a372fdfceaaee7d2e3c1342805aa6818df "Make sure the app model is initialized from the POMs provided by the
Maven plugin that could be manipulated by Maven extensions".

I create a example project at https://github.com/benstonezhang/multi-projects-quarkus-example.git for easy reproduce this issue.

Expected behavior

stack overflow should not happen.

Actual behavior

when run mvn package at the root of the project, the WorkspaceLoader enter an infinity loop and cause stack overflow finally.

Exception in thread "main" java.lang.StackOverflowError
	at java.base/jdk.internal.misc.Unsafe.copyMemoryChecks(Unsafe.java:831)
	at java.base/jdk.internal.misc.Unsafe.copyMemory(Unsafe.java:800)
	at java.base/sun.nio.fs.NativeBuffers.copyCStringToNativeBuffer(NativeBuffers.java:143)
	at java.base/sun.nio.fs.UnixNativeDispatcher.copyToNativeBuffer(UnixNativeDispatcher.java:50)
	at java.base/sun.nio.fs.UnixNativeDispatcher.exists(UnixNativeDispatcher.java:623)
	at java.base/sun.nio.fs.UnixFileSystemProvider.exists(UnixFileSystemProvider.java:538)
	at java.base/java.nio.file.Files.exists(Files.java:2521)
	at io.quarkus.bootstrap.resolver.maven.workspace.WorkspaceLoader.getParentPom(WorkspaceLoader.java:204)
	at io.quarkus.bootstrap.resolver.maven.workspace.WorkspaceLoader.loadProject(WorkspaceLoader.java:174)
	at io.quarkus.bootstrap.resolver.maven.workspace.WorkspaceLoader.loadProject(WorkspaceLoader.java:176)
	... ...
	at io.quarkus.bootstrap.resolver.maven.workspace.WorkspaceLoader.loadProject(WorkspaceLoader.java:176)

but if we run mvn package -f quarkus-example, there is no issue.

How to Reproduce?

Steps:

  1. git clone https://github.com/benstonezhang/multi-projects-quarkus-example.git
  2. cd multi-projects-quarkus-example
  3. mvn package

Output of uname -a or ver

Linux localhost 4.18.0-425.3.1.el8.x86_64 #1 SMP Wed Nov 9 20:13:27 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.17" 2022-10-18 LTS OpenJDK Runtime Environment (Red_Hat-11.0.17.0.8-2.el8_6) (build 11.0.17+8-LTS) OpenJDK 64-Bit Server VM (Red_Hat-11.0.17.0.8-2.el8_6) (build 11.0.17+8-LTS, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.13.0 and later

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.5.4 (Red Hat 3.5.4-5) Maven home: /usr/share/maven Java version: 17.0.5, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.5.0.8-2.el8_6.x86_64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "4.18.0-425.3.1.el8.x86_64", arch: "amd64", family: "unix"

Additional information

No response

@benstonezhang benstonezhang added the kind/bug Something isn't working label Dec 9, 2022
@geoand
Copy link
Contributor

geoand commented Dec 9, 2022

cc @aloubyansky

@benstonezhang
Copy link
Contributor Author

benstonezhang commented Dec 9, 2022

I made a patch, please review:

diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java
index a30aad09d2..9e2587ee65 100644
--- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java
+++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java
@@ -153,13 +153,11 @@ private LocalProject loadAndCacheProject(Path pomFile) throws BootstrapMavenExce
     }
 
     private Model rawModel(Path pomFile) throws BootstrapMavenException {
-        final Model rawModel = rawModelCache.getOrDefault(pomFile.getParent(),
+        Model rawModel = rawModelCache.getOrDefault(pomFile.getParent(),
                 modelProvider == null ? null : modelProvider.apply(pomFile.getParent()));
-        return rawModel == null ? loadAndCacheRawModel(pomFile) : rawModel;
-    }
-
-    private Model loadAndCacheRawModel(Path pomFile) throws BootstrapMavenException {
-        final Model rawModel = readModel(pomFile);
+        if (rawModel == null) {
+            rawModel = readModel(pomFile);
+        }
         rawModelCache.put(pomFile.getParent(), rawModel);
         return rawModel;
     }

@aloubyansky
Copy link
Member

@benstonezhang thanks for looking into it. Would you like to open a PR?

benstonezhang added a commit to benstonezhang/quarkus that referenced this issue Dec 11, 2022
@benstonezhang
Copy link
Contributor Author

PR #29784 created

@rsvoboda
Copy link
Member

rsvoboda commented Jan 9, 2023

PR is merged, can be the issues closed?

@benstonezhang
Copy link
Contributor Author

Verified on 2.15.1 and later.

@geoand
Copy link
Contributor

geoand commented Jan 9, 2023

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/bootstrap kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants