Skip to content

Fix resource leaking on error in AsyncCachingExec - #871

Merged
ok2c merged 1 commit into
apache:5.6.xfrom
Jouramie:feature/fix-async-caching-exec-resource-leak
Aug 14, 2026
Merged

Fix resource leaking on error in AsyncCachingExec#871
ok2c merged 1 commit into
apache:5.6.xfrom
Jouramie:feature/fix-async-caching-exec-resource-leak

Conversation

@Jouramie

Copy link
Copy Markdown
Contributor

When dataConsumer.consume throws, the resources allocated by the consumer are never released. This causes a memory leak, especially with zstd, since ZstdDecompressCtx allocates native memory in its init that must be freed explicitly.

Trace found while investigating the leak:

libasyncProfiler.so.malloc_hook()
com.github.luben.zstd.util.Native.load() [native malloc inside zstd-jni init]
com.github.luben.zstd.ZstdDecompressCtx.init()
com.github.luben.zstd.ZstdDecompressCtx.<init>() line: 27
org.apache.hc.client5.http.async.methods.InflatingZstdDataConsumer.<init>(AsyncDataConsumer) line: 68
org.apache.hc.client5.http.impl.async.ContentCompressionAsyncExec$$Lambda.apply(Object)
org.apache.hc.client5.http.impl.async.ContentCompressionAsyncExec$1.handleResponse(HttpResponse, EntityDetails) line: 159
[...]
org.apache.hc.client5.http.impl.async.AsyncHttpRequestRetryExec$1.handleResponse(...) line: 133
org.apache.hc.client5.http.impl.cache.AsyncCachingExec$1.handleResponse(...) line: 209
org.apache.hc.client5.http.impl.cache.AsyncCachingExec.triggerResponse(...) line: 130
org.apache.hc.client5.http.impl.cache.AsyncCachingExec.handleCacheHit(...) line: 748

This mostly happens when requests are cancelled, which causes consume() to throw.

The fix wraps the returned AsyncDataConsumer so releaseResources() is always called if consume() throws, since AsyncCachingExec.triggerResponse doesn't do this itself.

@ok2c
ok2c merged commit 8cec73f into apache:5.6.x Aug 14, 2026
8 checks passed
@ok2c

ok2c commented Aug 14, 2026

Copy link
Copy Markdown
Member

@Jouramie cherry-picked to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants