Repository navigation
HERESUP-98784: RetryExecutor to close the response it abandons, releasing the connection - #166
Merged
Merged
Conversation
…sing the connection A pooled HttpProvider ran out of connections after as many attempts as the pool holds per route, so the caller saw a connection-pool timeout instead of the response the server sent. A token fetch against a server answering 503, 503, 200 used to reach the server twice and fail; it now reaches it three times and returns the token.
ashishKhushiKumar
self-requested a review
October 14, 2026 09:39
ashishKhushiKumar
approved these changes
Oct 14, 2026
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.
HERESUP-98784
RetryExecutornever closes the response it abandons, so a pooledHttpProvidernever gets that connection back. Once every connection for the route has leaked this way, the next attempt blocks on the connection-request timeout and the call fails with a pool timeout instead of the status the server sent.HereAccessTokenProviderwith a stockApacheHttpClientProviderandSocket5xxExponentialRandomBackoffPolicy, against a server scripted503, 503, 200: before, two requests, thenConnectionPoolTimeoutExceptionafter ~11 s. After, three requests and the token.Affected: anyone passing a response-retrying policy to
setRetryPolicy/withRetryPolicy, in 0.4.33 through 0.4.36. Callers on theNoRetryPolicydefault are not.The fix closes the abandoned response before the next attempt starts. The closed response stays in the
RetryContext, so a policy sees exactly what it saw before, and the response handed back to the caller is never closed.Apache's
close()drains the body, so a 5xx whose body stalls now costs one read timeout before the retry. Against a server that sends a partial body then hangs, 8 ms became 5 s. Aborting instead is not reachable throughHttpProvider.HttpResponse.Also found, not fixed here
Socket5xxExponentialRandomBackoffPolicy.shouldRetry: thegetCause() instanceof SocketTimeoutExceptionarm sits outside themaxNumberOfRetriescheck. A connect timeout arrives in that shape, so an unreachable endpoint retries without bound.getNextRetryIntervalMilliscomputesretryIntervalMillis * nextInt(1 << retryCount)inint: 0 ms on about half of first retries, negative fromretryCount22,IllegalArgumentExceptionat 31.RetryExecutorswallowsInterruptedExceptionwithout restoring the interrupt flag.ApacheHttpClientProviderbuilds JSON bodies as a non-repeatableBasicHttpEntity, so a retried JSON-body request resends an empty body. Form-encoded requests, including the token endpoint, are fine.