Skip to content

Commit fffd034

Browse files
author
Ali Rizwan
committed
fix warnings generated because of connection leak
body should be closed ref: square/okhttp#2311 Currently warnings are generated from okhttp: ``` com.spotify.githubclient.shade.okhttp3.internal.platform.Platform log WARNING: A connection to https://ghe.spotify.net/ 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); ```
1 parent fa142d0 commit fffd034

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/main/java/com/spotify/github/v3/clients/GitHubClient.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,8 @@
5454
import java.util.function.Consumer;
5555
import javax.ws.rs.core.HttpHeaders;
5656
import javax.ws.rs.core.MediaType;
57-
import okhttp3.Call;
58-
import okhttp3.Callback;
59-
import okhttp3.OkHttpClient;
60-
import okhttp3.Request;
61-
import okhttp3.RequestBody;
62-
import okhttp3.Response;
57+
58+
import okhttp3.*;
6359
import org.slf4j.Logger;
6460
import org.slf4j.LoggerFactory;
6561

@@ -232,8 +228,8 @@ public static GitHubClient scopeForInstallationId(
232228
}
233229

234230
static String responseBodyUnchecked(final Response response) {
235-
try {
236-
return response.body().string();
231+
try (ResponseBody body = response.body()) {
232+
return body.string();
237233
} catch (IOException e) {
238234
throw new UncheckedIOException("Failed getting response body for: " + response, e);
239235
}
@@ -651,6 +647,10 @@ public void onResponse(final Call call, final Response response) {
651647
future.completeExceptionally(mapException(res, request));
652648
} catch (final Throwable e) {
653649
future.completeExceptionally(e);
650+
} finally {
651+
if (res.body() != null) {
652+
res.body().close();
653+
}
654654
}
655655
} else {
656656
future.complete(res);

0 commit comments

Comments
 (0)