gnodet commented on PR #30505:
URL: https://github.com/apache/camel/pull/30505#issuecomment-7102794087

   The push at 13:18 (1a3d8f1) already updated the class Javadoc to remove the 
"stop/restart" language — the description now says the ownership invariant and 
scopes each test to what it actually verifies.
   
   On the reproducer: I ran `tokenAndApiOnSameHostSucceeds` without the fix and 
confirmed it passes. As you noted, `HttpOAuth2AuthenticationTest` already 
covers same-host/port for the basic request path and passes on main. So that 
test is a sanity check, not a regression test.
   
   Here is where the fix matters. `InternalHttpClient.close()` drains its 
`closeables` queue. When `connManagerShared=false` (the original code), 
`HttpClientBuilder.build()` appends the `PoolingHttpClientConnectionManager` to 
that queue. The token client is built from the endpoint's builder with 
`connManagerShared=false`, so it owns the pool. The endpoint client is then 
built from the same builder (also `connManagerShared=false`), so it also owns 
the pool. Two separate `InternalHttpClient` instances, both with the pool in 
their `closeables`.
   
   `OAuth2ClientConfigurer.doStop()` closes the token client. That closes the 
pool. The subsequent `IOHelper.close(httpClient)` in `HttpEndpoint.doStop()` 
then tries to close the pool a second time — harmless since HC5's 
`PoolingHttpClientConnectionManager.close()` is idempotent — but any in-flight 
or future lease attempt after the token client's `close()` will see 
`IllegalStateException: Connection pool shut down`.
   
   The timing that maps to the JIRA: `doStop()` is reachable during a running 
route if the route supervisor stops and restarts the route on an error. With 
`timer:t repeatCount=2`, if the first exchange fails (say, the token server 
responds with `Connection: close` and HC5's retry exhausts its budget), the 
exchange is marked as failed. Depending on the error handler configuration or 
the Camel route supervisor, the route may be stopped. At that point 
`HttpEndpoint.doStop()` calls `ServiceHelper.stopService(..., 
httpClientConfigurer)` before the timer fires again, and the pool is closed. 
When the route restarts (or when HC5's `HttpRequestRetryExec` retries on the 
same `execute()` call), the pool is gone.
   
   With the fix (`connManagerShared=true` on the builder before the token 
client is built), `InternalHttpClient.close()` on the token client does not 
touch the pool. The pool stays alive until `HttpEndpoint.doStop()` explicitly 
closes it at line 406. That is the invariant 
`tokenClientCloseDoesNotShutDownEndpointPool` checks.
   
   I do not have `camel run` available in this environment to reproduce the 
exact YAML route from the JIRA against a local server. If you want to hold the 
port labels until that is confirmed, that is a reasonable call. The fix is 
correct for the ownership invariant, and I am confident it addresses the 
scenario — but I cannot produce the exact reproducer run you asked for.


-- 
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