Skip to content

Conversation

@CharlesDuboisSAP
Copy link
Contributor

@CharlesDuboisSAP CharlesDuboisSAP commented Dec 10, 2025

Context

SAP/ai-sdk-java-backlog#328.

HttpClient4 is very outdated

Feature scope:

  • Change internal Destination Service integration to HTTP Client 5

Definition of Done

  • Functionality scope stated & covered
  • Tests cover the scope above
  • Error handling created / updated & covered by the tests above
  • Documentation updated
  • Release notes updated

@CharlesDuboisSAP CharlesDuboisSAP self-assigned this Dec 10, 2025
@CharlesDuboisSAP CharlesDuboisSAP added the please review Request to review a pull request label Dec 10, 2025
@CharlesDuboisSAP CharlesDuboisSAP enabled auto-merge (squash) February 3, 2026 12:34
Copy link
Contributor

@newtork newtork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write a release note / compatibility note, indicating HttpClient 5 usage in destination retrieval. Users that overload the behavior for a workaround with HttpClientAccessor need to adopt and migrate to ApacheHttpClient5Accessor.

ClassicHttpResponse response =
ResilienceDecorator.executeSupplier(tpDestinationVerifierSupplier, resilienceConfiguration) ) {
verifyTransparentProxyResponse(response, destinationName);
EntityUtils.consume(response.getEntity());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Major)

Please do not do this.

The response.getEntity() needs to be consumes (i.e. closed), otherwise the connection stays open for long time and reserves a slot of the connection pool. If too many "verifyTransparentProxyResponse" executions fail, the pool will be full and future runs will result in timeouts, because the pool is not releasing connections. These errors are super difficult to debug, when it comes to that.

Therefore, the finally block is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a try-with-resources, it auto closes the response after the try. The entity consume night not even be necessary

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting topic, I tried to understand what happens when you don't consume the entity before closing. Apparently, that will close the connection but may not give it back to connection pool(?)

Image

We could test that by running like 500 HttpCient requests with closing but without consuming. If my concern is valid it will stop after 200 requests.

Since you are the one changing the code, you will test that :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

500 requests each with 1 second delay, all in parallel

Total time for 500 requests: 10762 ms

500 failing requests each with 1 second delay, all in parallel

Total time for 500 failing requests: 2187 ms

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore, it works without the consume

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it works without the consume

I confirm. "consume" is already being called implicitly. image

We could actually remove the explicit call here.

newtork
newtork previously approved these changes Feb 3, 2026
@CharlesDuboisSAP CharlesDuboisSAP merged commit 6c821c9 into main Feb 4, 2026
13 checks passed
@CharlesDuboisSAP CharlesDuboisSAP deleted the httpclient5-destination branch February 4, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

please review Request to review a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants