# Gradle hangs indefinately after finishing tests run in parallel

**URL:** <https://discuss.gradle.org/t/gradle-hangs-indefinately-after-finishing-tests-run-in-parallel/2147>\
**Category:** Old Forum Archive\
**Created:** [April 18, 2013, 8:29pm UTC](https://discuss.gradle.org/t/gradle-hangs-indefinately-after-finishing-tests-run-in-parallel/2147 "2013-04-18T20:29:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesper\_Thuun\_Peterse](https://avatars.discourse-cdn.com/v4/letter/j/b77776/32.png) [@Jesper\_Thuun\_Peterse](https://discuss.gradle.org/u/Jesper_Thuun_Peterse)\
**Post date:** [April 18, 2013, 8:29pm UTC](https://discuss.gradle.org/t/gradle-hangs-indefinately-after-finishing-tests-run-in-parallel/2147/1 "2013-04-18T20:29:00Z")

</div>

I have almost 4000 tests run by Gradle’s parallel threads test run functionality.

When the tests have finished running, the execution (in Jenkins) hangs for a long while. At the moment, I have a build hanging from last night, so it’s been hanging for more than eight hours. There’s no activity, and no db-connections.

We run exactly the same tests through ant, with no hanging or other problems.

If we kill the process manually, the following is written to the Jenkins log file. Are you able to deduce anything from this information?

Stacktraces from both parent and child processes: [https://gist.github.com/anonymous/5419590](https://gist.github.com/anonymous/5419590)

Regards /Jesper Thuun-Petersen

---

<div class="post-metadata">

**Author:** ![mzbrand](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@mzbrand](https://discuss.gradle.org/u/mzbrand)\
**Post date:** [April 19, 2013, 1:39pm UTC](https://discuss.gradle.org/t/gradle-hangs-indefinately-after-finishing-tests-run-in-parallel/2147/2 "2013-04-19T13:39:00Z")

</div>

We may be seeing the same thing. The tests run fine under ant, but when we run them under Gradle they appear to run for awhile and then the process just hangs. I haven’t had time to investigate further, but it sounds like the same issue.

Does anyone know anything more about this?

---

<div class="post-metadata">

**Author:** ![djangofan](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/djangofan/32/117_2.png) [@djangofan](https://discuss.gradle.org/u/djangofan)\
**Post date:** [April 19, 2013, 4:30pm UTC](https://discuss.gradle.org/t/gradle-hangs-indefinately-after-finishing-tests-run-in-parallel/2147/3 "2013-04-19T16:30:00Z")

</div>

Yes, in the past I have encountered this problem before. I found that it is caused by not closing objects correctly at the end of tests. In other words, a object that was instantiated during a test is remaining open and so Gradle wont finish until you mark/delete it properly so it can be garbage collected.

---

<div class="post-metadata">

**Author:** ![Jesper\_Thuun\_Peterse](https://avatars.discourse-cdn.com/v4/letter/j/b77776/32.png) [@Jesper\_Thuun\_Peterse](https://discuss.gradle.org/u/Jesper_Thuun_Peterse)\
**Post date:** [April 22, 2013, 6:37am UTC](https://discuss.gradle.org/t/gradle-hangs-indefinately-after-finishing-tests-run-in-parallel/2147/4 "2013-04-22T06:37:00Z")

</div>

We’ve sort of fixed this issue. As I’ve reported earlier, we have problems with gradle throwing stackOverflowExceptions when certain exceptions escape our tests: [http://forums.gradle.org/gradle/topics/gradle\_does\_not\_gracefully\_handle\_test\_exits](http://forums.gradle.org/gradle/topics/gradle_does_not_gracefully_handle_test_exits).

Apparently, we had a part of our testcode not wrapped in the harness the Gradle folks recommended to work around the overflow-bug, and when we safe guarded this piece of code as well, the hanging problem went away!

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [April 22, 2013, 9:40am UTC](https://discuss.gradle.org/t/gradle-hangs-indefinately-after-finishing-tests-run-in-parallel/2147/5 "2013-04-22T09:40:00Z")

</div>

@Jesper: I don’t quite understand what’s happened here as it’s spread over several topics.

Do you think there is something for us to “fix” for this particular issue?

---

<div class="post-metadata">

**Author:** ![Jesper\_Thuun\_Peterse](https://avatars.discourse-cdn.com/v4/letter/j/b77776/32.png) [@Jesper\_Thuun\_Peterse](https://discuss.gradle.org/u/Jesper_Thuun_Peterse)\
**Post date:** [April 22, 2013, 12:50pm UTC](https://discuss.gradle.org/t/gradle-hangs-indefinately-after-finishing-tests-run-in-parallel/2147/6 "2013-04-22T12:50:00Z")

</div>

@Luke: understandable - I don’t understand much of this behavior either. I have linked the issues, because I felt they might be related.

In this issue, we had eight processes running tests i parallel. Each process worked on it’s own database. One of these db’s had failed the create script, however, and some kind of exception were thrown. This probably went out to the Gradle test control process.

As we have seen in the related issue, db-exceptions can cause gradle to throw stackOverflows. We tried wrapping the exception in a RuntimeException like we do for all our other testcases (recommended by Peter N). This made the testcase fail normally and not freeze!

I hope this makes more sense now?

Regards /Jesper

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [April 22, 2013, 1:47pm UTC](https://discuss.gradle.org/t/gradle-hangs-indefinately-after-finishing-tests-run-in-parallel/2147/7 "2013-04-22T13:47:00Z")

</div>

I’m going to mark this down as a duplicate of [http://forums.gradle.org/gradle/topics/strange\_exception\_thrown\_running\_unit\_tests](http://forums.gradle.org/gradle/topics/strange_exception_thrown_running_unit_tests).

The symptom may not be the same, but I think it’s the same root cause.
