gnodet opened a new pull request, #30505:
URL: https://github.com/apache/camel/pull/30505

   ## Summary
   
   Fix `camel-http`: when the OAuth2 token endpoint is on the same host and 
port as the API endpoint, requests fail with `IllegalStateException: Connection 
pool shut down`.
   
   ## Root Cause
   
   `OAuth2ClientConfigurer.configureHttpClient(HttpClientBuilder 
clientBuilder)` built the token HTTP client by calling `clientBuilder.build()` 
on the builder that the endpoint had already set its own 
`HttpClientConnectionManager` on.
   
   Because `connManagerShared` defaults to `false`, both the token client and 
the endpoint's main client considered themselves the owner of that connection 
manager. When the token client was closed (via `doStop()`), it shut down the 
shared pool. The main client then found the pool shut down and threw 
`IllegalStateException: Connection pool shut down` on the next connection lease.
   
   This manifests specifically when the token endpoint and API endpoint share 
the same host and port — a very common pattern (e.g. 
`https://api.example.com/oauth/token` as the token endpoint for 
`https://api.example.com/items`).
   
   ## Fix
   
   Build the token client from a fresh `HttpClientBuilder.create()` instead of 
reusing the endpoint's configured builder. This gives the token client its own 
independent connection manager that cannot interact with the endpoint's pool.
   
   ```java
   // Before
   this.httpClient = clientBuilder.build();
   
   // After
   this.httpClient = HttpClientBuilder.create().build();
   ```
   
   ## Tests
   
   `HttpOAuth2SameHostPoolShutdownTest` with two methods:
   
   1. **`tokenAndApiOnSameHostSucceeds`** — integration test using a single 
server on one port that serves both `/token` and `/items`; two successive 
requests through an OAuth2-configured endpoint both succeed.
   
   2. **`tokenClientCloseDoesNotShutDownEndpointPool`** — unit test that 
directly simulates the lifecycle: creates an `OAuth2ClientConfigurer`, calls 
`configureHttpClient`, stops the configurer (closing the token client), then 
verifies the endpoint's connection pool is still leasable. Fails with 
`IllegalStateException: Connection pool shut down` on unfixed code, passes 
after the fix.
   
   Full `camel-http` test suite: 319 tests run, 0 failures, 0 errors.
   
   Fixes CAMEL-27233
   
   ---
   _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to