WARNING on connection leak of response body.

304 views
Skip to first unread message

Chao Wang

unread,
Feb 16, 2017, 3:27:51 AM2/16/17
to GitHub Java API (http://github-api.kohsuke.org/)
Hi all,

When I follow the last section about OkHttp in http://github-api.kohsuke.org/ to use pluggable connector with OkHttp. I sometimes see warning message in log:

15:53:14,467 WARNING [com.squareup.okhttp.OkHttpClient] (OkHttp ConnectionPool) A connection to https://api.github.com/ was leaked. Did you forget to close a response body?


Basically, I think it is caused by some intermittent internet failures to retrieve data from GitHub, once a sub-task (let's say get Pull Request) reaches timeout in Future get() method due to network difficulty, I can catch a CancellationException, I think in that case I should somehow close a response body as pointed by the warning message and also in https://github.com/square/okhttp/issues/2311. But I did not see where I can do it. After I configure the connector as:
 
Cache cache = new Cache(cacheFile, size * 1024 * 1024); // default 20MB cache
                }
RepositoryConfig config = ...
GitHub github = new GitHubBuilder()
                        .withOAuthToken(config.getPassword(), config.getUsername())
                        .withConnector(new OkHttpConnector(new OkUrlFactory(new OkHttpClient().setCache(cache))))
                        .build();


I have no other place to deal with the OkHttpConnector and OkHttpClient, it only calls github.getXXX() method to retrieve data from GitHub without any response body I can access to close off.

Any idea how can I fix the potential leak here ?

versions  I use:
okhttp-urlconnection version 2.7.5
github-api version 1.77

Reply all
Reply to author
Forward
0 new messages