<html><body><div dir="ltr"><div>
</div><div><div dir="ltr">You Can take an Heap dump and Check how many selectormanager Instances you have and who own them. Maybe you had close/reconnects or Deal with multiple Class Loaders?</div><div dir="ltr"><br></div><div dir="ltr">Gruß</div><div dir="ltr">Bernd</div><div id="ms-outlook-mobile-signature"><div style="direction: ltr;">-- </div><div style="direction: ltr;">http://bernd.eckenfels.net</div></div>
<div> </div><hr style="display:inline-block;width:98%" tabindex="-1"><div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif"><b>Von:</b> net-dev <net-dev-retn@openjdk.org> im Auftrag von Ruslan Ibragimov <ruslan@heapy.io><br><b>Gesendet:</b> Donnerstag, Januar 23, 2025 7:59 PM<br><b>An:</b> net-dev@openjdk.org <net-dev@openjdk.org><br><b>Betreff:</b> Dozens of "HttpClient-N-SelectorManager" threads created<div> </div></font></div><div>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.<br><br>I'm creating only one instance of HttpClient in whole application, and confirming with logging that following snippet called only once:<br><br></div><pre style="border: 1px solid rgb(204, 204, 204); border-radius: 3px; background-repeat: repeat; background-attachment: scroll; background-image: none; background-size: auto; background-origin: padding-box; background-clip: border-box; font-family: menlo, consolas, monospace; font-size: 90%; margin: 7px 0px; padding: 7px 10px; background-color: rgb(246, 246, 246);"><div><span class="color" style="color: rgb(207, 142, 109);">val </span>httpClient = HttpClient.newBuilder()<br style="max-width:100%; height:auto"></div><div> .version(HttpClient.Version.<span class="color" style="color: rgb(199, 125, 187);"><i>HTTP_2</i></span>)<br style="max-width:100%; height:auto"></div><div> .followRedirects(HttpClient.Redirect.<span class="color" style="color: rgb(199, 125, 187);"><i>NEVER</i></span>)<br style="max-width:100%; height:auto"></div><div> .connectTimeout(Duration.ofSeconds(<span class="color" style="color: rgb(42, 172, 184);">60</span>))<br style="max-width:100%; height:auto"></div><div> .build()<br style="max-width:100%; height:auto"></div></pre><div><br>I also verified that no dependencies using HttpClient under the hood.<br><br></div><pre style="border: 1px solid rgb(204, 204, 204); border-radius: 3px; background-repeat: repeat; background-attachment: scroll; background-image: none; background-size: auto; background-origin: padding-box; background-clip: border-box; font-family: menlo, consolas, monospace; font-size: 90%; margin: 7px 0px; padding: 7px 10px; background-color: rgb(246, 246, 246);">"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(java.base@17.0.13/Native Method)
at sun.nio.ch.EPollSelectorImpl.doSelect(java.base@17.0.13/EPollSelectorImpl.java:118)
at sun.nio.ch.SelectorImpl.lockAndDoSelect(java.base@17.0.13/SelectorImpl.java:129)
- locked <0x000000008c488e38> (a sun.nio.ch.Util$2)
- locked <0x000000008c488de8> (a sun.nio.ch.EPollSelectorImpl)
at sun.nio.ch.SelectorImpl.select(java.base@17.0.13/SelectorImpl.java:141)
at jdk.internal.net.http.HttpClientImpl$SelectorManager.run(java.net.http@17.0.13/HttpClientImpl.java:894)
Locked ownable synchronizers:
- None<br style="max-width:100%; height:auto"></pre><div><br><br>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).<br><br>Any hint to understand why this might happen and how to debug root cause would be appreciated.<br> <br></div><div id="sig116664320"><div class="signature">--<br></div><div class="signature">Best regards,<br></div><div class="signature">Ruslan Ibragimov<br></div><div class="signature"><a href="https://heapy.io/">https://heapy.io/</a><br></div></div><div dir="ltr"><br></div></div><div id="ms-outlook-mobile-signature"><div><br></div><div><br></div><div style="direction:ltr">-- </div><div style="direction:ltr">http://bernd.eckenfels.net</div></div></div></body></html>