HTTPCLIENT-2416 - Fix pool entry leak on late lease completion#809
Open
arturobernalg wants to merge 1 commit intoapache:masterfrom
Open
HTTPCLIENT-2416 - Fix pool entry leak on late lease completion#809arturobernalg wants to merge 1 commit intoapache:masterfrom
arturobernalg wants to merge 1 commit intoapache:masterfrom
Conversation
f8fc570 to
1865484
Compare
ok2c
reviewed
Mar 5, 2026
| } catch (final TimeoutException | InterruptedException ex) { | ||
| if (!leaseFuture.cancel(true)) { | ||
| try { | ||
| final PoolEntry<HttpRoute, ManagedHttpClientConnection> latePoolEntry = leaseFuture.get( |
Member
There was a problem hiding this comment.
@arturobernalg If the method fails once the proposed fix to call another time? That does not look right. There has to be a better fix.
Member
Author
There was a problem hiding this comment.
@ok2c I dropped the second get() and reworked it to use the pool.lease(..., FutureCallback) to capture late completions and release the PoolEntry on timeout/interrupt/cancel.
90770d4 to
c48f2af
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.
This patch fixes a race in PoolingHttpClientConnectionManager#lease().
When LeaseRequest#get(...) exits with TimeoutException or InterruptedException, the current code calls leaseFuture.cancel(true). If the underlying lease completes just before cancellation is observed, cancel(true) returns false and the PoolEntry can remain leased, because no ConnectionEndpoint was returned to the caller and nothing releases it.
The fix handles that case in the exceptional path: if cancel(true) returns false, the code attempts a zero-timeout get() on the lease future and, if a late-completed PoolEntry is obtained, releases it immediately back to the pool.