# Integration testing in Java, carrotsearch thread leaks & severe errors

**URL:** <https://discuss.elastic.co/t/integration-testing-in-java-carrotsearch-thread-leaks-severe-errors/26831>\
**Category:** Elasticsearch\
**Created:** [August 4, 2015, 7:51pm UTC](https://discuss.elastic.co/t/integration-testing-in-java-carrotsearch-thread-leaks-severe-errors/26831 "2015-08-04T19:51:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nomlaran](https://avatars.discourse-cdn.com/v4/letter/n/b19c9b/32.png) [@nomlaran](https://discuss.elastic.co/u/nomlaran)\
**Post date:** [August 4, 2015, 7:51pm UTC](https://discuss.elastic.co/t/integration-testing-in-java-carrotsearch-thread-leaks-severe-errors/26831/1 "2015-08-04T19:51:35Z")

</div>

Every time I run my integration test (which extends ElasticsearchIntegrationTest) I get a thread leak severe log message from carrotsearch. What I've found in googling for a resolution to this suggests that this was fixed a long time ago. But I'm still seeing it with version 1.7.0 of org.elasticsearch:elasticsearch (regular dependency as well as test-jar), 2.1.13 of com.carrotsearch.randomizedtesting:randomizedtesting-runner and 4.10.4 of org.apache.lucene:lucene-test-framework. I've also tried with 1.7.1, 2.1.16 and 5.2.1 respectively but run into other dependency issues when I do that.

My test base class is set up like so:

```
@ElasticsearchIntegrationTest.ClusterScope(scope= ElasticsearchIntegrationTest.Scope.TEST)
abstract public class ReportingFullStackIT extends ElasticsearchIntegrationTest {
...
}

```

And the exception I get is this:

```
Aug 04, 2015 12:13:15 PM com.carrotsearch.randomizedtesting.ThreadLeakControl checkThreadLeaks
WARNING: Will linger awaiting termination of 5 leaked thread(s).
Aug 04, 2015 12:13:20 PM com.carrotsearch.randomizedtesting.ThreadLeakControl checkThreadLeaks
SEVERE: 2 threads leaked from SUITE scope at com.foo.stuff.MyTestIT: 

```

... abbreviated

```
Aug 04, 2015 12:13:20 PM com.carrotsearch.randomizedtesting.ThreadLeakControl tryToInterruptAll
INFO: Starting to interrupt leaked threads:
   1) Thread[id=88, name=metrics-meter-tick-thread-1, state=TIMED_WAITING, group=TGRP-MyTestIT]
   2) Thread[id=89, name=metrics-meter-tick-thread-2, state=WAITING, group=TGRP-MyTestIT]
Aug 04, 2015 12:13:23 PM com.carrotsearch.randomizedtesting.ThreadLeakControl tryToInterruptAll
SEVERE: There are still zombie threads that couldn't be terminated:

```

... abbreviated

```
Throwable:
com.carrotsearch.randomizedtesting.ThreadLeakError: There are still zombie threads that couldn't be terminated:

```

... abbreviated

```
        at java.lang.Thread.run(Thread.java:745)
	at __randomizedtesting.SeedInfo.seed([C0B4BC6EAE06585B]:0)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    __randomizedtesting.SeedInfo.seed([C0B4BC6EAE06585B]:0)

```

... abbreviated

```
   2) Thread[id=89, name=metrics-meter-tick-thread-2, state=WAITING, group=TGRP-MyTestIT]
        at sun.misc.Unsafe.park(Native Method)
        at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
        at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1088)
        at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
        at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
    __randomizedtesting.SeedInfo.seed([C0B4BC6EAE06585B]:0)

Process finished with exit code 255

```

From what I can tell, it looks like the issue is in \_\_randomizedtesting.SeedInfo.seed. I don't understand why this is happening though.

Is it possible that the docs are wrong?  
[https://www.elastic.co/guide/en/elasticsearch/reference/1.6/using-elasticsearch-test-classes.html](https://www.elastic.co/guide/en/elasticsearch/reference/1.6/using-elasticsearch-test-classes.html)

---

<div class="post-metadata">

**Author:** ![Marcus\_Widegren](https://avatars.discourse-cdn.com/v4/letter/m/9de053/32.png) [@Marcus\_Widegren](https://discuss.elastic.co/u/Marcus_Widegren)\
**Post date:** [September 15, 2015, 7:18am UTC](https://discuss.elastic.co/t/integration-testing-in-java-carrotsearch-thread-leaks-severe-errors/26831/2 "2015-09-15T07:18:01Z")

</div>

I'm also having this exact issue. Have you been able to solve, or work around, it?

Cheers  
/Marcus

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 15, 2015, 7:32am UTC](https://discuss.elastic.co/t/integration-testing-in-java-carrotsearch-thread-leaks-severe-errors/26831/3 "2015-09-15T07:32:39Z")

</div>

I'm also getting that in two cases:

- my test fails and somehow some threads are not stopped. Basically fix the test and this error will disappear
- I added some static variables within the test class using `@BeforeClass`. At the end of the test, you need to create an `@AfterClass` and set static variable to `null`. Also, if you started some processes within the test, make sure you are stopping all of them.

If possible, avoid any static initialization in your test class.

Hope this helps

---

<div class="post-metadata">

**Author:** ![jeremysanecki](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeremysanecki/32/610_2.png) [@jeremysanecki](https://discuss.elastic.co/u/jeremysanecki)\
**Post date:** [October 1, 2015, 6:46pm UTC](https://discuss.elastic.co/t/integration-testing-in-java-carrotsearch-thread-leaks-severe-errors/26831/4 "2015-10-01T18:46:46Z")

</div>

I had the same issue, and was able to fix it by adding the following to the test class...

```
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)

```

I got the answer from this github issue, [https://github.com/elastic/elasticsearch/issues/8642](https://github.com/elastic/elasticsearch/issues/8642)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:47pm UTC](https://discuss.elastic.co/t/integration-testing-in-java-carrotsearch-thread-leaks-severe-errors/26831/5 "2017-07-05T23:47:10Z")

</div>


