Possible Gradle wrapper race condition when concurrently executing


(Tim Fox) #1

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

https://vertx.ci.cloudbees.com/job/vert.x%20mod-lang-jruby/593/console

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:

https://github.com/gradle/gradle/blob/master/subprojects/wrapper/src/main/java/org/gradle/wrapper/Install.java#L49

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.


(Tim Fox) #2

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:

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


(Luke Daley) #3

Looks suspicious to me too. Raised as GRADLE-2699.

Thanks for the detailed report and suggestion.


(Luke Daley) #4

This has been fixed for a while in the nightlies if you need some immediate relief for this problem. It will be in 1.6 which is about 5 weeks away.

If you want to use a nightly, you can get info from http://gradle.org/nightly.

Thanks for the report.