[GRADLE-2699] Gradle wrapper race condition when concurrently executing Created: 07/Mar/13  Updated: 25/Mar/13  Resolved: 25/Mar/13

Status: Resolved
Project: Gradle
Affects Version/s: 1.4
Fix Version/s: 1.6-rc-1

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Fixed Votes: 0


We've been getting errors such as this from the Gradle Wrapper quite frequently when running Gradle builds on cloudbees CI:


I decided to look at the code in the Gradle Wrapper to see what it was doing around this time, and I noticed a possible race condition that could be causing the problem:


If two or more builds are running as the same user on the same machine at the same time (which is normal in a CI environment), then it appears two or more builds could end up trying to unzip the distribution at the same time and deleting the tmp file from under the feet of the other one.

I haven't tried to debug this - this is just a guess looking at some suspicious code.
[1] https://vertx.ci.cloudbees.com/job/vert.x%20mod-lang-jruby/593/console
[2] https://github.com/gradle/gradle/blob/master/subprojects/wrapper/src/main/java/org/gradle/wrapper/Install.java#L49

Comment by Gradle Forums [ 07/Mar/13 ]

One way of fixing this would be to generate the temp download file name using a random UUID to (virtually) eliminate the possibility of clashes, then use an atomic rename to rename the file (if it doesn't already exist) when the download is complete:

[1]http://docs.oracle.com/javase/7/docs/..., java.nio.file.Path, java.nio.file.CopyOption...)
[1] http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html#move(java.nio.file.Path

Generated at Wed Jun 30 12:29:05 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.