Fix Apache HttpClient 5 reactor recovery#2034
Open
sharp-pixel wants to merge 3 commits into
Open
Conversation
27d4ae0 to
3004731
Compare
andrross
reviewed
Jun 30, 2026
Comment on lines
+219
to
+220
| * Releases the (potentially very large) response buffer and converts a fatal {@link OutOfMemoryError} into a | ||
| * recoverable {@link IOException}. |
Member
There was a problem hiding this comment.
I'm not sure it is safe to do this. The contract of java.lang.Error generally is that it "indicates serious problems that a reasonable application should not try to catch". I don't think you can assume the JVM is in a workable state after observing an error and the right thing to do is let the process crash. In this case, you don't actually know if the response buffer in question here caused the OOM, versus something else in the application unrelated to this client that consumed all the heap.
Member
|
Would it make sense to break this into 2 PRs? One with the fix to allow recovery from reactor shutdowns, and another PR with the changes to reduce the chance of reactor-killing memory failures. |
Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
Signed-off-by: Cédric Pelvet <cedric.pelvet@gmail.com>
3004731 to
a6d50d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1969
Problem
ApacheHttpClient5Transportcould enter an unrecoverable state after Apache HttpClient 5 reportedIOReactorShutdownException. Once the underlying I/O reactor was shut down, the transport continued using the same deadCloseableHttpAsyncClient, so every later request failed until the application recreated the transport.One common trigger is memory pressure while buffering large or highly concurrent responses. The existing per-response buffer limit capped a single response, but it did not cap aggregate heap usage across concurrent responses, so many in-flight responses could still exhaust the heap and kill the reactor.
Solution
This change makes
ApacheHttpClient5Transportrecover from reactor shutdowns when it owns the client lifecycle:IOReactorShutdownExceptionis detected.execute(...)failures and callback-delivered reactor shutdown failures.It also reduces the chance of reactor-killing memory failures:
OutOfMemoryErrorduring response buffering into a request-levelIOExceptionso the reactor thread is not killed.Testing
Ran:
Also verified the locally published modified client in a standalone sample app using the normal existing transport builder path against OpenSearch 3.7.0 in Docker: