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

**URL:** <https://discuss.gradle.org/t/build-hangs-randomly-with-gradle-2-8-similar-to-gradle-3027/12823>\
**Category:** Bugs\
**Tags:** gradle-3027, issue-acknowledged\
**Created:** [November 18, 2015, 10:35pm UTC](https://discuss.gradle.org/t/build-hangs-randomly-with-gradle-2-8-similar-to-gradle-3027/12823 "2015-11-18T22:35:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ithildir](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ithildir/32/2782_2.png) [@Ithildir](https://discuss.gradle.org/u/Ithildir)\
**Post date:** [November 18, 2015, 10:35pm UTC](https://discuss.gradle.org/t/build-hangs-randomly-with-gradle-2-8-similar-to-gradle-3027/12823/1 "2015-11-18T22:35:49Z")

</div>

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 😕

You can have a look at the thread dump here: [https://gist.github.com/Ithildir/8cc456669907a3527875](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](https://github.com/gradle/gradle/blob/master/subprojects/dependency-management/src/main/java/org/gradle/api/internal/artifacts/ivyservice/ivyresolve/parser/GradlePomModuleDescriptorBuilder.java#L186) 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! 😊

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [November 19, 2015, 12:39am UTC](https://discuss.gradle.org/t/build-hangs-randomly-with-gradle-2-8-similar-to-gradle-3027/12823/2 "2015-11-19T00:39:53Z")

</div>

Thanks, it looks like the same thing to me.

[https://github.com/gradle/gradle/commit/9c7ca9b2ac4d8ba17fab76ac1e5ea38e78d41de5](https://github.com/gradle/gradle/commit/9c7ca9b2ac4d8ba17fab76ac1e5ea38e78d41de5) removed the call to IvyUtil, which I think was a mistake.

I reopened GRADLE-3027

---

<div class="post-metadata">

**Author:** ![Ithildir](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ithildir/32/2782_2.png) [@Ithildir](https://discuss.gradle.org/u/Ithildir)\
**Post date:** [November 19, 2015, 12:43am UTC](https://discuss.gradle.org/t/build-hangs-randomly-with-gradle-2-8-similar-to-gradle-3027/12823/3 "2015-11-19T00:43:33Z")

</div>

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 😄

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [November 19, 2015, 12:48am UTC](https://discuss.gradle.org/t/build-hangs-randomly-with-gradle-2-8-similar-to-gradle-3027/12823/4 "2015-11-19T00:48:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mark\_vieira](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/mark_vieira/32/5396_2.png) [@mark\_vieira](https://discuss.gradle.org/u/mark_vieira)\
**Post date:** [November 25, 2015, 7:13pm UTC](https://discuss.gradle.org/t/build-hangs-randomly-with-gradle-2-8-similar-to-gradle-3027/12823/5 "2015-11-25T19:13:07Z")

</div>

This will be fixed in Gradle 2.10.

> <https://github.com/gradle/gradle/commit/0cdb5c18908a3094066b556c5bddce9a3dc2a8a6>
