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

   _Claude Code on behalf of seshuthota_
   
   JIRA: [CAMEL-26110](https://issues.apache.org/jira/browse/CAMEL-26110)
   
   ## Description
   
   When an AS2 partner answers with `Connection: close`, the client put the 
closed connection back in its pool. A send within the next 2 seconds (before 
the pool's stale check, `validateAfterInactivity`) leased it and failed with 
`NoHttpResponseException: The target server failed to respond`.
   
   `AS2ClientConnection.send()` released every connection with the keep-alive 
of its strategy: `NEG_ONE` for a `Connection: close` response, and `ZERO` when 
there was no response. In HttpClient 5 (5.6.4 and 5.6.5), 
`PoolingHttpClientConnectionManager.release()` closes a connection only for a 
`null` keep-alive, and `PoolEntry.updateExpiry()` keeps a non-positive one with 
no expiry. So both values kept the connection, the opposite of what the code 
intended.
   
   The `finally` block of `send()` now releases with `null`, which closes the 
connection, when there is no response, or when HttpCore's 
`DefaultConnectionReuseStrategy` says the connection cannot be reused 
(`Connection: close`, an HTTP/1.0 response without keep-alive, a response body 
without a length). Otherwise it releases with the strategy's keep-alive, as 
before. The strategy's `Connection: close` branch is removed, since that case 
no longer reaches it.
   
   The `ZERO` case did not cause a failure on its own: 
`HttpRequestExecutor.execute()` already closes the connection on an exception. 
It now uses `null` too, as davsclaus suggested on #28265, so the comment and 
the behaviour agree.
   
   Not changed: a `Keep-Alive: timeout=0` header or an `httpConnectionPoolTtl` 
of 0 still give a zero keep-alive, which keeps the connection with no expiry. 
Treating them as "do not keep" would change the meaning of a configured TTL, so 
it is left for a separate discussion.
   
   ## Tests
   
   - New `AS2ClientConnectionReuseTest` (3 tests) in camel-as2-api, with a 
small in-test partner that counts the connections carrying a request:
     - `Connection: close` response, 3 sends in a row: each gets a new 
connection
     - HTTP/1.0 response without keep-alive: same
     - kept-alive response: the 3 sends share one connection
   - The first two fail on main with `NoHttpResponseException`. A mutant that 
always closes the connection fails the third.
   - Against Camel's own `AS2ServerConnection`, 5 sends through one client:
     - The server answers an error (a 500 from its request handler) with 
`Connection: close`. On main the closed connection stayed in the pool and the 
second send failed with `NoHttpResponseException`; with the fix all 5 sends get 
their answer.
     - On success (200 with keep-alive), main and the fix behave the same: one 
pooled connection serves all 5 sends.
   - Full camel-as2 build: 110 (api) + 19 (component, 1 skipped as before) + 
111 (integration) tests pass. Formatter and impsort applied; no generated files 
change.
   - Combined with #28265 (CAMEL-25941, which changes the same `send()` 
method): no merge conflict, and all camel-as2 tests pass on the merge (110 + 33 
+ 111).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_0132kd6FojYDmowiTV4jkrvW
   


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