Jouramie opened a new pull request, #871:
URL: https://github.com/apache/httpcomponents-client/pull/871

   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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to