I am using OkHttp 3, and I keep getting leaked connection warnings:
WARNING: A connection to https://help.helpling.com/ was leaked. Did you forget to close a response body?
Jul 14, 2016 6:57:09 PM okhttp3.ConnectionPool pruneAndGetAllocationCount
Everytime I get a ResponseBody
, I either call .string()
which supposedly closes the stream for me, or I explicitly close it in a finally
block, in the following way:
ResponseBody responseBody = response.body();
try (Reader responseReader = responseBody.charStream()) {
...
}
finally {
responseBody.close();
}
My application makes intense use of the network, and yet that warning appears frequently. I never observed any problem caused by this presumed leak, but I would still like to understand if and what I am doing wrong.
Could anyone shed some light on this?