I encounter strange behavior of java.net.http.HttpClient in my application
running in amazoncorretto:17.0.13, after some time instead of just one
HttpClient-1-SelectorManager thread I'm starting observing dozens of such
threads.
I'm creating only one instance of HttpClient in whole application, and
confirming with logging that following snippet called only once:
val httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.*HTTP_2*)
.followRedirects(HttpClient.Redirect.*NEVER*)
.connectTimeout(Duration.ofSeconds(60))
.build()
I also verified that no dependencies using HttpClient under the hood.
"HttpClient-18-SelectorManager" #20791 daemon prio=5 os_prio=0 cpu=31.77ms
elapsed=3679.62s allocated=178K defined_classes=0 tid=0x00007f212c5dfce0
nid=0x541f runnable [0x00007f21993ee000]
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.EPoll.wait([email protected]/Native Method)
at
sun.nio.ch.EPollSelectorImpl.doSelect([email protected]/EPollSelectorImpl.java:118)
at
sun.nio.ch.SelectorImpl.lockAndDoSelect([email protected]/SelectorImpl.java:129)
- locked <0x000000008c488e38> (a sun.nio.ch.Util$2)
- locked <0x000000008c488de8> (a sun.nio.ch.EPollSelectorImpl)
at
sun.nio.ch.SelectorImpl.select([email protected]/SelectorImpl.java:141)
at
jdk.internal.net.http.HttpClientImpl$SelectorManager.run([email protected]/HttpClientImpl.java:894)
Locked ownable synchronizers:
- None
So now I'm in situation when I see a lot (a few times they grow to 150+
threads) of such threads created over time and stay alive. I believe it's also
hurting application performance which lead even to timeouts on http stack (but
this is unconfirmed).
Any hint to understand why this might happen and how to debug root cause would
be appreciated.
--
Best regards,
Ruslan Ibragimov
https://heapy.io/