-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
[Bug] Maven commands fail randomly in CI/CD workflow #123
Comments
Hi @tschaffter
No I haven't. sorry
I would say so too, yes. It has nothing to do with the plugin per se, but rather in the concurrent capabilities of the projects that were ran.
Yes that would be a good test indeed. You could also try to pinpoint from the
in a loop, could help reproduce the issue locally... Looking at the source code of Maven itself, can also help: |
I spent some time exploring the issue and came up with a solution. The issue stems from the fact that concurrent executions of Maven is not safe. For example, two or more concurrent executions of Maven may attempt to download the same dependency at the same time and save it to A similar error occurs when multiple project targets that rely on $ nx run-many --all target=build
...
Exception in thread "main" java.util.zip.ZipException: zip END header not found
at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1469)
at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1477)
at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1315)
at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1277)
at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:709)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:243)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:172)
at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:186)
Exception in thread "main" java.nio.file.NoSuchFileException: /root/.m2/wrapper/dists/apache-maven-3.8.6-bin/67568434/apache-maven-3.8.6-bin.zip.part
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at org.apache.maven.wrapper.Installer.unzip(Installer.java:207)
at org.apache.maven.wrapper.Installer.createDist(Installer.java:110)
at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:151)
at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:76)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:429)
at java.base/sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:266)
at java.base/java.nio.file.Files.move(Files.java:1432)
at org.apache.maven.wrapper.Installer.createDist(Installer.java:95)
at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:151)
at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:76)
Exception in thread "main" java.nio.file.NoSuchFileException: /root/.m2/wrapper/dists/apache-maven-3.8.6-bin/67568434/apache-maven-3.8.6-bin.zip.part
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:429)
at java.base/sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:266)
at java.base/java.nio.file.Files.move(Files.java:1432)
at org.apache.maven.wrapper.Installer.createDist(Installer.java:95)
at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:151)
at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:76) The above issues become more and more likely to happen randomly as the Nx workspace grows in terms of number of Maven-based projects. Ultimately, I decided to find a solution to "prepare-java": {
"executor": "@nrwl/workspace:run-commands",
"options": {
"commands": [
"./mvnw dependency:go-offline -DexcludeGroupIds=org.sagebionetworks.challenge || true"
],
"cwd": "apps/challenge-api-gateway"
}
}, This target downloads Maven ( In my CI workflow, I run the following command to ultimately 1) install Maven and 2) install all the project dependencies (minus my shared local libraries) sequentially for the affected projects. - run: yarn nx affected --target=prepare-java --parallel=1
- run: yarn nx affected --target=lint
- run: yarn nx affected --target=build
- run: yarn nx affected --target=test This solves The release notes of the latest version of Maven mention improvements for concurrent builds. I have not evaluated the impact of these improvements on the reported issues but it sounded like a good time to update the version of Maven used by the wrapper, and update the wrapper itself at the same occasion. For each Java project, I update the distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar Once again, anyone using this plugin should face |
Hi Thomas, Thanks for your continuing interest in the plugin and for sharing the result of your investigation in such an exhaustive way! I will look into a way to implement (and document) your workaround, with:
My only concern so far, is the compatibility when using Gradle (instead of Maven) as build system... I'm still researching the best way to achieve that, that would be transparent for final users of the plugin, wether they use Maven or Gradle. |
We've also ran into several problems with this, which forced us to disable parallel builds, sadly. But there seems to be workarounds to make maven concurrent safe. Maybe you coud add it into your plugin? http://takari.io/book/30-team-maven.html#concurrent-safe-local-repository |
This is still an issue for my monorepos where I have to run some Gradle tasks with without concurrency. The Takari project seems archive. One of their GH repo indicates that there may be a solution for projects managed with Maven: https://maven.apache.org/resolver/local-repository.html#shared-access-to-local-repository |
Plugin Name
@nxrocks/nx-spring-boot
Plugin Version
4.1.0
Nx Version
14.4.3
Expected Behaviour
./mvnw
commands should successfully completes on first execution.Actual Behaviour
This project provides the script
./mvnw
to run maven commands when executing project targets (e.g.nx build <project>
). In my main CI/CD workflow (GH Action), the execution of targets that rely on./mvnw
randomly fail.Here are the high-level commands that may fail in my CI/CD work.
Here is an example of error that randomly make my CI/CD workflow fail.
Restarting the failed job in the GH Actions may lead to a successful run as well as another failed run (seems random).
Based on the log, could it be that maven or the maven wrapper (
./mvnw
) executions can not be reliably run in parallel? I run 2-3 tasks in parallel in my CI/CD workflow. The next troubleshooting step would be for me to test without running targets concurrently.@tinesoft Have you ever observed this behavior with
./mvnw
?Steps to reproduce the behaviour
.github/workflows/ci.yml
may randomly fail.The text was updated successfully, but these errors were encountered: