-
Notifications
You must be signed in to change notification settings - Fork 39
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
race condition in FileUtils.copyFile() #47
Comments
also raised in Maven dependencies plugin: https://issues.apache.org/jira/browse/MDEP-633 |
Can you provide a minimal viable example project for this? I'd assume even if you have one shared output dir the parallel builders build disjoint stuff. |
Just need a parent with two children |
|
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy-dependencies (default-cli) on project mod1: Error copying artifact from /home/X/.m2/repository/org/quickfixj/quickfixj-messages-all/2.1.0/quickfixj-messages-all-2.1.0-javadoc.jar to /home/X/workspace-gitlab/my_sandbox/mdep633/mod1/../target/quickfixj-messages-all-2.1.0-javadoc.jar: Failed to copy full contents from /home/X/.m2/repository/org/quickfixj/quickfixj-messages-all/2.1.0/quickfixj-messages-all-2.1.0-javadoc.jar to /home/X/workspace-gitlab/my_sandbox/mdep633/mod1/../target/quickfixj-messages-all-2.1.0-javadoc.jar -> [Help 1] |
|
@michael-o please see test case above |
@gregallen Thanks for the case. This is, of course, a conceptual problem. I guess this case was never considered. How do you want to make it thread-safe? It need some locking mechanism. I do not unterstand how the amount of written bytes will help if two threads are writing the same moment with different regions. Do you have a PR you'd like to propose? I am all ears.. |
@michael-o I suggest that the low-level file writing method should return the total number of bytes written, and that is what you should check against the size of the source file. Do not attempt to check the size of the destination file, since another racing thread may have already "accidentally" deleted (or truncated) the newly copied file, and be in the middle of re-copying it. It's not ideal that the file gets copied twice, but not a big deal. Not worth trying to devise some locking approach to avoid that. Instead just simplify the check IMHO |
Looks like |
OR, get rid of the check altogether - the javadoc for |
@gregallen Is it an option to refactor the pom files so that each module copy files to its own directory, then merge those directories into one in a later phase? seems to me that the plugin is not designed to concurrently copy the same files into a common directory. |
no, that would not be possible. There are 150 modules, and 95% of the dependencies are identical. However, there are a few modules that require differing versions of some artifacts, so it is also not possible to do the copy from a single module (since that would only copy one version per artifact). The build runs with 20x parallelism, so the race condition is often seen |
What is the scenario in which the File.length() check adds value? In the out-of-diskspace case, doesn't an IOException get thrown? |
in a parallel multi-module maven build, running copy-dependencies with a shared output directory...
more than one module may attempt to copy the file at once. The length check can then fail since it sees the size of the partially copied new file.
suggest using the return value from nio Files copyFile, which is the number of bytes copied. can be safely compared against the size of the source file.
also, you can surely rip out the old pre-nio code and drop java 6 support?
The text was updated successfully, but these errors were encountered: