Build hangs randomly with Gradle 2.8, similar to GRADLE-3027


We’re facing an issue on our CI servers while building a fairly large multi-project (around 500 projects), with parallel and configuration-on-demand both enabled. Sometimes, Gradle just hangs while running, and the moment when it hangs seems to be random… I couldn’t find any pattern :confused:

You can have a look at the thread dump here: These parts are especially interesting:

"Task worker" prio=10 tid=0x096ef400 nid=0x7e14 runnable [0x073fd000]
    java.lang.Thread.State: RUNNABLE
        at java.util.WeakHashMap.get(
        at org.gradle.api.internal.artifacts.ivyservice.IvyUtil.createModuleId(
        - locked <0x358744e8> (a java.lang.Object)
        at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.PomReader$PomDependencyMgtElement.getExcludedModules(


"Task worker Thread 2" prio=10 tid=0x096efc00 nid=0x7e15 waiting for monitor entry [0x071fd000]
    java.lang.Thread.State: BLOCKED (on object monitor)
        at org.gradle.api.internal.artifacts.ivyservice.IvyUtil.createModuleId(
        - waiting to lock <0x358744e8> (a java.lang.Object)
        at org.gradle.api.internal.artifacts.ivyservice.moduleconverter.DefaultExcludeRuleConverter.createExcludeRule(

It really looks like GRADLE-3027, which is marked as resolved. If I understand, you centralized all the calls to Ivy’s ModuleId.newInstance and ModuleRevisionId.newInstance in IvyUtil, so you could synchronize them and avoid the WeakHashMap bug. However, this line in GradlePomModuleDescriptorBuilder does not use IvyUtil. I did some debugging, and it seems that ModuleId.intern (which is not thread-safe) is only called from IvyUtil or from this Gradle class.

What do you think about it? For now, we’ll try to replace that call with IvyUtil and use a patched version.

Thank you! :blush:

Thanks, it looks like the same thing to me. removed the call to IvyUtil, which I think was a mistake.

I reopened GRADLE-3027

Good, thank you! Do you want a PR or you’ll fix it? I would like to make my first contribution to Gradle, but it’s only 1 line :smile:

I think we can handle it. I was going to see if there were any other cases and if there’s something we can do to catch this in the future.

This will be fixed in Gradle 2.10.