IBM / cloudant-java-sdk

Cloudant SDK for Java
Apache License 2.0
22 stars 17 forks source link

Cloudant Java SDK does not properly close the OkHttp Response #472

Closed uliSchuster closed 1 year ago

uliSchuster commented 1 year ago

Describe the bug

I am using the Cloudant Java SDK Version 0.5.6 to access a local CouchDb. During operation, I encountered a serialization error, which caused a retry. During the retry, the following warning appeared:

2023-09-13 12:17:21 WARN OkHttpClient:133 - A connection to http://couchdb:5984/ was leaked. Did you forget to close a response body? To see where this was allocated, set the OkHttpClient logger level to FINE: Logger.getLogger(OkHttpClient.class.getName()).setLevel(Level.FINE);

To Reproduce Try to retrieve a document such that the request fails, and then retry that request multiple times.

Expected behavior The Response object returned from the service call should be closed properly, also when the request fails for some reason.

Must gather (please complete the following information):

Additional context

This seems to result from not properly closing the Response resource returned by the underlying OkHttp library, as described here. In fact, a look at the method processServiceCall() in com.ibm.cloud.sdk.core.service.BaseService does not show a call to Response.close() anywhere

mojito317 commented 1 year ago

Hi Ulrich!

I need more details to repro this bug:

If you use one of the asStream methods it's your responsibility to close the InputStream.

mojito317 commented 1 year ago

Closing as stale.