[httpclient] HTTP2: Memory Leak with Proxy

Albert Schimpf albi646 at gmx.de
Tue Aug 7 09:25:36 UTC 2018


Hi,

I stumbled upon some strange behavior when using the new Java httpclient.

The issue is very simple to reproduce. Send a GET request via a known 
bad proxy:

HttpClient client = HttpClient.newBuilder()
                     .proxy(ProxySelector.of(BAD_PROXY))
                     .build();

HttpRequest req = HttpRequest
                     // target is not relevant
                     .newBuilder(...)
                     .GET()
                     .build();

// body handler is not relevant
HttpResponse.BodyHandler<?> t = HttpResponse.BodyHandler.asString();

// happens with both async and sync send
client.sendAsync(req, t).get(30, TimeUnit.SECONDS);

The result is that the heap size increases dramatically (to about 1.5GB) 
and resources are not released. CPU consumption increases by a constant 
factor, too. I have tried many variations of the above code, and the 
only thing which seems to work (i.e. heap size does not explode) is to 
set the HTTP version to 1.1.

In my main application this leads to both memory and CPU starvation (4GB 
memory limit, 100% CPU usage). It usually uses only 5% CPU and 200MB 
memory at worst.

I have attached a working example code with a bad proxy. I uploaded the 
generated garbage collection log and three heap dumps (before, during, 
and after the request) to dropbox:

https://www.dropbox.com/s/ulqnmrmgr58rrul/debug.zip

I tried the 10.0.0-openjdk and 10.0.1-zulu version. I can reproduce the 
issue 100% of times.

Am I doing something wrong? Is this to be expected if one somehow 
happens to use a bad proxy? If this is to be expected, how can I protect 
my application against such behavior?


Best,
Albert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mon.png
Type: image/png
Size: 64534 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20180807/7de59329/mon-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.java
Type: text/x-java
Size: 1866 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20180807/7de59329/Main-0001.java>


More information about the net-dev mailing list