[
https://issues.apache.org/jira/browse/NUTCH-2624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16555659#comment-16555659
]
ASF GitHub Bot commented on NUTCH-2624:
---------------------------------------
sebastian-nagel closed pull request #367: NUTCH-2624 protocol-okhttp resource
leak
URL: https://github.com/apache/nutch/pull/367
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttpResponse.java
b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttpResponse.java
index b720c287f..5e861c7f9 100644
---
a/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttpResponse.java
+++
b/src/plugin/protocol-okhttp/src/java/org/apache/nutch/protocol/okhttp/OkHttpResponse.java
@@ -94,42 +94,44 @@ public OkHttpResponse(OkHttp okhttp, URL url, CrawlDatum
datum)
Request request = rb.build();
okhttp3.Call call = okhttp.getClient().newCall(request);
- okhttp3.Response response = call.execute();
+ // ensure that Response and underlying ResponseBody are closed
+ try (okhttp3.Response response = call.execute()) {
- Metadata responsemetadata = new Metadata();
- okhttp3.Headers httpHeaders = response.headers();
+ Metadata responsemetadata = new Metadata();
+ okhttp3.Headers httpHeaders = response.headers();
- for (int i = 0, size = httpHeaders.size(); i < size; i++) {
- String key = httpHeaders.name(i);
- String value = httpHeaders.value(i);
+ for (int i = 0, size = httpHeaders.size(); i < size; i++) {
+ String key = httpHeaders.name(i);
+ String value = httpHeaders.value(i);
- if (key.equals(REQUEST) || key.equals(RESPONSE_HEADERS)) {
- value = new String(Base64.getDecoder().decode(value));
- }
+ if (key.equals(REQUEST) || key.equals(RESPONSE_HEADERS)) {
+ value = new String(Base64.getDecoder().decode(value));
+ }
- responsemetadata.add(key, value);
- }
- LOG.debug("{} - {} {} {}", url, response.protocol(), response.code(),
- response.message());
-
- TruncatedContent truncated = new TruncatedContent();
- content = toByteArray(response.body(), truncated, okhttp.getMaxContent(),
- okhttp.getMaxDuration(), okhttp.isStorePartialAsTruncated());
- responsemetadata.add(FETCH_TIME,
Long.toString(System.currentTimeMillis()));
- if (truncated.booleanValue()) {
- if (!call.isCanceled()) {
- call.cancel();
+ responsemetadata.add(key, value);
+ }
+ LOG.debug("{} - {} {} {}", url, response.protocol(), response.code(),
+ response.message());
+
+ TruncatedContent truncated = new TruncatedContent();
+ content = toByteArray(response.body(), truncated, okhttp.getMaxContent(),
+ okhttp.getMaxDuration(), okhttp.isStorePartialAsTruncated());
+ responsemetadata.add(FETCH_TIME,
+ Long.toString(System.currentTimeMillis()));
+ if (truncated.booleanValue()) {
+ if (!call.isCanceled()) {
+ call.cancel();
+ }
+ responsemetadata.set(TRUNCATED_CONTENT, "true");
+ responsemetadata.set(TRUNCATED_CONTENT_REASON,
+ truncated.getReason().toString().toLowerCase(Locale.ROOT));
+ LOG.debug("HTTP content truncated to {} bytes (reason: {})",
+ content.length, truncated.getReason());
}
- responsemetadata.set(TRUNCATED_CONTENT, "true");
- responsemetadata.set(TRUNCATED_CONTENT_REASON,
- truncated.getReason().toString().toLowerCase(Locale.ROOT));
- LOG.debug("HTTP content truncated to {} bytes (reason: {})",
- content.length, truncated.getReason());
- }
-
- code = response.code();
- headers = responsemetadata;
+ code = response.code();
+ headers = responsemetadata;
+ }
}
private final byte[] toByteArray(final ResponseBody responseBody,
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> protocol-okhttp resource leak
> -----------------------------
>
> Key: NUTCH-2624
> URL: https://issues.apache.org/jira/browse/NUTCH-2624
> Project: Nutch
> Issue Type: Bug
> Components: protocol
> Affects Versions: 1.15
> Reporter: Sebastian Nagel
> Priority: Major
> Fix For: 1.15
>
>
> The protocol-okhttp leaks response streams as logged by
> okhttp3.ConnectionPool:
> {noformat}
> WARNING: A connection to ... was leaked. Did you forget to close a response
> body?
> {noformat}
> This has been introduced in commit
> [f598db7|https://github.com/apache/nutch/commit/f598db7] - need to catch the
> IOException *and* close the response, then re-throw so that FetcherThread can
> handle the exception.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)