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

concurrent extracting of nested jars fails #917

Closed
Bananeweizen opened this issue Apr 26, 2022 · 6 comments
Closed

concurrent extracting of nested jars fails #917

Bananeweizen opened this issue Apr 26, 2022 · 6 comments
Milestone

Comments

@Bananeweizen
Copy link
Contributor

I just had an error where two parallel tycho builds tried to extract the same nested jar, and the second build failed. Tycho does the extracting by replacing an existing target file, therefore this fails while the file is locked.
However, in my case it would have been the exact same file and version, so it would not have been necessary to try and replace the file, but just use the existing file in the second of the two builds. Can we eventually improve the logic there to skip extracting if the identical version is already there? Or can we eventually use different folders for extracting from different running processes?

[ERROR] Internal error: java.lang.RuntimeException: java.lang.RuntimeException: IOException while extracting 'annotations.jar' from C:\Users\userid\.m2\repository\p2\osgi\bundle\org.eclipse.pde.ds.lib\1.1.500.v20210209-1250\org.eclipse.pde.ds.lib-1.1.500.v20210209-1250.jar: C:\Users\userid\.m2\repository\.cache\tycho\org.eclipse.pde.ds.lib-1.1.500.v20210209-1250.jar\annotations.jar: The process cannot access the file because it is being used by another process. -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: java.lang.RuntimeException: IOException while extracting 'annotations.jar' from C:\Users\userid\.m2\repository\p2\osgi\bundle\org.eclipse.pde.ds.lib\1.1.500.v20210209-1250\org.eclipse.pde.ds.lib-1.1.500.v20210209-1250.jar
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:120)
        at org.apache.maven.cli.DaemonMavenCli.execute(DaemonMavenCli.java:825)
        at org.apache.maven.cli.DaemonMavenCli.doMain(DaemonMavenCli.java:244)
        at org.apache.maven.cli.DaemonMavenCli.main(DaemonMavenCli.java:222)
        at org.mvndaemon.mvnd.daemon.Server.handle(Server.java:573)
        at org.mvndaemon.mvnd.daemon.Server.client(Server.java:262)
        at org.mvndaemon.mvnd.daemon.Server.accept(Server.java:230)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: IOException while extracting 'annotations.jar' from C:\Users\userid\.m2\repository\p2\osgi\bundle\org.eclipse.pde.ds.lib\1.1.500.v20210209-1250\org.eclipse.pde.ds.lib-1.1.500.v20210209-1250.jar
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
        at java.base/java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:600)
        at java.base/java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
        at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.resolveProjects(TychoMavenLifecycleParticipant.java:164)
        at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProjectsRead(TychoMavenLifecycleParticipant.java:105)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:264)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
        ... 7 common frames omitted
Caused by: java.lang.RuntimeException: IOException while extracting 'annotations.jar' from C:\Users\userid\.m2\repository\p2\osgi\bundle\org.eclipse.pde.ds.lib\1.1.500.v20210209-1250\org.eclipse.pde.ds.lib-1.1.500.v20210209-1250.jar
        at org.eclipse.tycho.core.osgitools.DefaultBundleReader.getEntry(DefaultBundleReader.java:133)
        at org.eclipse.tycho.core.osgitools.OsgiBundleProject.getNestedJarOrDir(OsgiBundleProject.java:547)
        at org.eclipse.tycho.core.osgitools.OsgiBundleProject.getBundleClasspath(OsgiBundleProject.java:513)
        at org.eclipse.tycho.core.osgitools.OsgiBundleProject.resolveClassPath(OsgiBundleProject.java:231)
        at org.eclipse.tycho.core.resolver.DefaultTychoResolver.resolveProject(DefaultTychoResolver.java:173)
        at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.lambda$resolveProjects$0(TychoMavenLifecycleParticipant.java:147)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.stream.SpinedBuffer.forEach(SpinedBuffer.java:250)
        at java.base/java.util.stream.Nodes$SpinedNodeBuilder.forEach(Nodes.java:1270)
        at java.base/java.util.stream.Nodes$InternalNodeSpliterator$OfRef.forEachRemaining(Nodes.java:1105)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        at java.base/java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
        at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        at java.base/java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:408)
        at java.base/java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:736)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:159)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
        at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.lambda$resolveProjects$2(TychoMavenLifecycleParticipant.java:161)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1407)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Caused by: java.nio.file.FileSystemException: C:\Users\userid\.m2\repository\.cache\tycho\org.eclipse.pde.ds.lib-1.1.500.v20210209-1250.jar\annotations.jar: The process cannot access the file because it is being used by another process.

        at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
        at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:274)
        at java.base/sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:110)
        at java.base/java.nio.file.Files.deleteIfExists(Files.java:1181)
        at java.base/java.nio.file.Files.copy(Files.java:3055)
        at org.eclipse.tycho.core.osgitools.DefaultBundleReader.copyStreamToFile(DefaultBundleReader.java:172)
        at org.eclipse.tycho.core.osgitools.DefaultBundleReader.extractZipEntries(DefaultBundleReader.java:151)
        at org.eclipse.tycho.core.osgitools.DefaultBundleReader.getEntry(DefaultBundleReader.java:126)
        ... 26 common frames omitted
@laeubi
Copy link
Member

laeubi commented Apr 26, 2022

What Tycho version are you using? Please keep in mind that sharing the same maven repository with different processes can always cause corruption because maven repository is not thread safe!

@Bananeweizen
Copy link
Contributor Author

2.5. I'm not able to upgrade to 2.7.x due to Java 15 still being in use and the upgrade to 17 taking more time. Looking at the Tycho source I also don't think the DefaultBundleReader has changed there, or why do you think the version matters? This is not related to the ConcurrentModificationException that was fixed via P2 upstream changes, right?

@laeubi
Copy link
Member

laeubi commented Apr 26, 2022

I'm not able to upgrade to 2.7.x due to Java 15 still being in use and the upgrade to 17 taking more time

I must confess I'm not up to date with all that java versions still using java 11 :-)
I'm just remembering an issue with that code fixed that sounds very similar: #663

@Bananeweizen
Copy link
Contributor Author

Ah, that is the exact same exception, but the use case is slightly different. The fix is for one multi module build with parallel builder, and there using concurrent data structures etc. should be sufficient. In my case it's two separate tycho builds, therefore the check using the cache will not be successful, and the second build still tries to extract the file and will fail at the file copy operation as before. If I'm reading the code correctly, then we would need to check for the physical jar file existing (independent of the cache) before entering line 136: https://github.com/eclipse/tycho/blob/master/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/DefaultBundleReader.java#L136, similar to how this is already done for directories in line 118: https://github.com/eclipse/tycho/blob/master/tycho-core/src/main/java/org/eclipse/tycho/core/osgitools/DefaultBundleReader.java#L118.
Does that sound reasonable? If so, I could create a patch, but I have no idea how to test this.

@laeubi
Copy link
Member

laeubi commented Apr 26, 2022

As mentioned before, running two tycho processes that operate on the same maven-repository is highly discouraged as the maven-repository is not multi process safe!

@akurtakov
Copy link
Member

I think we can close this one as no work is planned or even could be done on tycho side.

@laeubi laeubi added this to the 3.0 milestone Sep 21, 2022
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

No branches or pull requests

3 participants