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

Hi!

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: https://gist.github.com/Ithildir/8cc456669907a3527875. 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(WeakHashMap.java:471)
        at org.apache.ivy.core.module.id.ModuleId.intern(ModuleId.java:63)
        at org.apache.ivy.core.module.id.ModuleId.newInstance(ModuleId.java:48)
        at org.gradle.api.internal.artifacts.ivyservice.IvyUtil.createModuleId(IvyUtil.java:79)
        - locked <0x358744e8> (a java.lang.Object)
        at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.PomReader$PomDependencyMgtElement.getExcludedModules(PomReader.java:529)

and

"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(IvyUtil.java:78)
        - waiting to lock <0x358744e8> (a java.lang.Object)
        at org.gradle.api.internal.artifacts.ivyservice.moduleconverter.DefaultExcludeRuleConverter.createExcludeRule(DefaultExcludeRuleConverter.java:30)

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.

https://github.com/gradle/gradle/commit/9c7ca9b2ac4d8ba17fab76ac1e5ea38e78d41de5 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.