Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unirest Thread Leak

My web app seems to be running out of memory which I think is due to a thread leak. It seems that threads are being stuck at waiting and this grows larger and larger until the memory reaches the top of the heap size. The thread size increases on my local Tomcat Server of the web app while idling and not using the web application. I don't have a great understanding of thread leaks but i'm sure threads are mean to be released to free up allocated memory.

I have taken a thread dump and a lot of these threads are waiting on com.mashape.unirest.http.utils.SyncIdleConnectionMonitorThread as shown below.

"Thread-124" - Thread t@378
java.lang.Thread.State: TIMED_WAITING
at java.lang.Object.wait(Native Method)
- waiting on <44c53e01> (a com.mashape.unirest.http.utils.SyncIdleConnectionMonitorThread)
at com.mashape.unirest.http.utils.SyncIdleConnectionMonitorThread.run(SyncIdleConnectionMonitorThread.java:22)

Locked ownable synchronizers:
- None

"Thread-122" - Thread t@371
java.lang.Thread.State: TIMED_WAITING
at java.lang.Object.wait(Native Method)
- waiting on <3212c7ae> (a com.mashape.unirest.http.utils.SyncIdleConnectionMonitorThread)
at com.mashape.unirest.http.utils.SyncIdleConnectionMonitorThread.run(SyncIdleConnectionMonitorThread.java:22)

Locked ownable synchronizers:
- None

Any helpful tips to solve this issue would be appreciated.

like image 981
Stefza Avatar asked Dec 12 '19 16:12

Stefza


1 Answers

This seems to be a bug in mashape Unirest if you create multiple unirest instances it doesn't close off the thread.

I have started using konghq version of unirest and it had fixed the problem.

It can be found here: https://mvnrepository.com/artifact/com.konghq/unirest-java

like image 159
Stefza Avatar answered Oct 10 '22 04:10

Stefza