Skip to content

Commit

Permalink
Properly close response body (#15)
Browse files Browse the repository at this point in the history
Avoid `WARNING: A connection to http://example.com was leaked. Did you
forget to close a response body?`
  • Loading branch information
JakobEdding authored Sep 5, 2024
1 parent 72e1fe2 commit f9dcc08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
`java-library`
id("com.bakdata.release") version "1.4.0"
id("com.bakdata.sonar") version "1.4.0"
id("com.bakdata.sonatype") version "1.4.0"
id("com.bakdata.sonatype") version "1.4.1"
id("io.freefair.lombok") version "8.4"
id("java-test-fixtures")
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/bakdata/kserve/client/KServeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.jetbrains.annotations.NotNull;

/**
Expand Down Expand Up @@ -100,7 +101,9 @@ private static ObjectMapper createObjectMapper() {
}

private static String getStringBody(final Response response) throws IOException {
return response.body().string();
try (ResponseBody body = response.body()) {
return body.string();
}
}

private static <T> Optional<T> processJsonResponse(final String stringBody, final Class<? extends T> responseType) {
Expand Down

0 comments on commit f9dcc08

Please sign in to comment.