-
Notifications
You must be signed in to change notification settings - Fork 614
Ensure proper closure of httpResponse in error scenarios during retries
#2497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
PR review rate limit exceeded |
httpResponse in error scenarios during ret…httpResponse in error scenarios during retries
|
lgtm! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds explicit closing of the HTTP response in the retry loop to prevent potential connection leaks and cleans up some imports and Javadoc links.
- Ensure
ClassicHttpResponseis closed on exception paths during retries - Simplify URL instantiation and catch clauses by updating imports
- Correct Javadoc link reference for
setClientCertificate
| try { | ||
| httpResponse.close(); | ||
| } catch (IOException ex) { | ||
| throw new ClientException("Failed to close response", e); |
Copilot
AI
Jul 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ClientException is wrapping the original exception e instead of the IOException ex from the close operation. It should pass ex as the cause to accurately represent the close failure.
| throw new ClientException("Failed to close response", e); | |
| throw new ClientException("Failed to close response", ex); |
| try { | ||
| httpResponse.close(); | ||
| } catch (IOException ex) { | ||
| throw new ClientException("Failed to close response", e); |
Copilot
AI
Jul 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing a ClientException inside the close catch block will exit the retry loop prematurely, potentially skipping further retry attempts. Consider logging the close error instead and allowing the retry logic to continue.
| throw new ClientException("Failed to close response", e); | |
| LOG.error("Failed to close response", ex); |
| Endpoint selectedEndpoint = getNextAliveNode(); | ||
| RuntimeException lastException = null; | ||
| for (int i = 0; i <= retries; i++) { | ||
| ClassicHttpResponse httpResponse = null; |
Copilot
AI
Jul 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider using a try-with-resources statement for ClassicHttpResponse to ensure it's always closed automatically, simplifying the error-handling logic.
…tent resource cleanup.
|
I have been running this overnight and have not seen any of the leaks I was seeing. TBH, I feel like the entire way HTTP connections are being handled and closed needs to be rewritten in a safer way. The way it works right now is too complicated - transport is intertwined with the logic of the Client API. Happy to contribute a proposal for that as a follow up to this PR. |
|
@orsondmc Thank you for the contribution! |
|
My pleasure |
Summary
May resolve #1741 . In error cases, the httpResponse is not closed and this could lead to a connection leak.