# Trouble with httpClient .getAsync Callbacks

**URL:** <https://forum.inductiveautomation.com/t/trouble-with-httpclient-getasync-callbacks/81306>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [November 1, 2023, 2:45pm UTC](https://forum.inductiveautomation.com/t/trouble-with-httpclient-getasync-callbacks/81306 "2023-11-01T14:45:57Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 2, 2023, 11:44am UTC](https://forum.inductiveautomation.com/t/trouble-with-httpclient-getasync-callbacks/81306/21 "2023-11-02T11:44:18Z")

</div>

> [@paul-griffith](#):
>
> but not until then

Which means: don't create the httpClient inside a function. Create it as a top-level variable in a project library script, so it will live a long time.

---

<div class="post-metadata">

**Author:** ![Cole\_Townsend](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cole_townsend/32/53149_2.png) [@Cole\_Townsend](https://forum.inductiveautomation.com/u/Cole_Townsend)\
**Post date:** [November 2, 2023, 1:26pm UTC](https://forum.inductiveautomation.com/t/trouble-with-httpclient-getasync-callbacks/81306/22 "2023-11-02T13:26:46Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/b/ebb8859821f00f8eb398c409b4fd237e27f52351.png)  
Moved all my client instants to top-level variables yesterday afternoon, and ever since then my bounded socket count has been steady. Thought you would be interested perhaps. Worked a charm, thank you Phil.

---

<div class="post-metadata">

**Author:** ![Cole\_Townsend](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cole_townsend/32/53149_2.png) [@Cole\_Townsend](https://forum.inductiveautomation.com/u/Cole_Townsend)\
**Post date:** [November 2, 2023, 5:27pm UTC](https://forum.inductiveautomation.com/t/trouble-with-httpclient-getasync-callbacks/81306/23 "2023-11-02T17:27:40Z")

</div>

If possible, a big note on the httpClient docs page strongly saying not to instantiate httpClient objects with function calls would probably be pertinent.

Took me about a week of digging before I realized where the problem was coming from, let alone what the problem was, as port exhaustion is a hard problem to catch in the logs for someone who hasn't dealt with it before, like me.

Otherwise, I could see other people creating httpClient objects at a slow rate, and then a month later when they run out of ephemeral ports the server starts having issues.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 2, 2023, 5:44pm UTC](https://forum.inductiveautomation.com/t/trouble-with-httpclient-getasync-callbacks/81306/24 "2023-11-02T17:44:59Z")

</div>

@paul-griffith have you reproduced this? Are the HttpClient objects leaking? Or do they get GC'd but somehow don't clean themselves up?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 2, 2023, 5:52pm UTC](https://forum.inductiveautomation.com/t/trouble-with-httpclient-getasync-callbacks/81306/25 "2023-11-02T17:52:17Z")

</div>

I've tried various times in the past to get httpClients and/or promise/response/etc objects to cause resource leaks and never succeeded. One common thread in user reports seems to be Windows, but even testing on Windows I've never succeeded.

I do think there's an issue, but I don't think it's in our own code, I think it's underlying in the JDK. I'm planning to explore explicit closing or making our HttpClient a context manager or something once we're on 21.

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [November 2, 2023, 9:14pm UTC](https://forum.inductiveautomation.com/t/trouble-with-httpclient-getasync-callbacks/81306/26 "2023-11-02T21:14:56Z")

</div>

A year ago, I ended up troubleshooting this situation and found it to be a bug in the JDK related to HTTP/2 connections, which are the default (see IGN-5334 on our side for more details). We added the `version` argument on `system.net.httpClient` so you could specify `version=HTTP_1_1`, which solved the lingering `CLOSE_WAIT` connections on Windows.

[Previous page](https://forum.inductiveautomation.com/t/trouble-with-httpclient-getasync-callbacks/81306.md?page=1)
