Skip to content

Commit

Permalink
Always close ResponseBody from okHttp
Browse files Browse the repository at this point in the history
should fix hyperledger-web3j#710
by implementing square/okhttp#2311
  • Loading branch information
antonydenyer committed Jun 4, 2019
1 parent f99ceb1 commit 2064833
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions core/src/main/java/org/web3j/protocol/http/HttpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,21 @@ protected InputStream performIO(String request) throws IOException {

okhttp3.Response response = httpClient.newCall(httpRequest).execute();
ResponseBody responseBody = response.body();
if (response.isSuccessful()) {
if (responseBody != null) {
return buildInputStream(responseBody);
try {
if (response.isSuccessful()) {
if (responseBody != null) {
return buildInputStream(responseBody);
} else {
return null;
}
} else {
return null;
}
} else {
int code = response.code();
String text = responseBody == null ? "N/A" : responseBody.string();
int code = response.code();
String text = responseBody == null ? "N/A" : responseBody.string();

throw new ClientConnectionException("Invalid response received: " + code + "; " + text);
throw new ClientConnectionException("Invalid response received: " + code + "; " + text);
}
} finally {
responseBody.close();
}
}

Expand Down

0 comments on commit 2064833

Please sign in to comment.