You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2026/08/14 09:09:16 UTC

(httpcomponents-client) branch 5.6.x updated: Fix resource leaking on error in AsyncCachingExec

This is an automated email from the ASF dual-hosted git repository.

ok2c pushed a commit to branch 5.6.x
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/5.6.x by this push:
     new 8cec73fed Fix resource leaking on error in AsyncCachingExec
8cec73fed is described below

commit 8cec73fed4de462bf70c8232d2d35e7dabab7966
Author: Jeremie Bolduc <16...@users.noreply.github.com>
AuthorDate: Thu Aug 13 14:36:30 2026 -0400

    Fix resource leaking on error in AsyncCachingExec
---
 .../org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java    | 7 ++++++-
 .../hc/client5/http/async/methods/InflatingZstdDataConsumer.java   | 4 +++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
index 6398155be..82db5e5c6 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AsyncCachingExec.java
@@ -126,8 +126,9 @@ private void triggerResponse(
         final SimpleBody body = cacheResponse.getBody();
         final byte[] content = body != null ? body.getBodyBytes() : null;
         final ContentType contentType = body != null ? body.getContentType() : null;
+        AsyncDataConsumer dataConsumer = null;
         try {
-            final AsyncDataConsumer dataConsumer = asyncExecCallback.handleResponse(
+            dataConsumer = asyncExecCallback.handleResponse(
                     cacheResponse,
                     content != null ? new BasicEntityDetails(content.length, contentType) : null);
             if (dataConsumer != null) {
@@ -139,6 +140,10 @@ private void triggerResponse(
             asyncExecCallback.completed();
         } catch (final HttpException | IOException ex) {
             asyncExecCallback.failed(ex);
+        } finally {
+            if (dataConsumer != null) {
+                dataConsumer.releaseResources();
+            }
         }
     }
 
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/InflatingZstdDataConsumer.java b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/InflatingZstdDataConsumer.java
index 3e633bfe9..da924a52c 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/InflatingZstdDataConsumer.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/async/methods/InflatingZstdDataConsumer.java
@@ -130,7 +130,9 @@ public void streamEnd(final List<? extends Header> trailers) throws HttpExceptio
 
     @Override
     public void releaseResources() {
-        dctx.close();
+        if (closed.compareAndSet(false, true)) {
+            dctx.close();
+        }
         downstream.releaseResources();
     }
 }
\ No newline at end of file