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

   ## Description
   
   JIRA: https://issues.apache.org/jira/browse/CAMEL-27890 (found through the 
flaky test CAMEL-27880)
   
   When the netty-http consumer rejects a request because the basic auth 
credentials are missing or invalid, it wrote the 401 response and closed the 
channel, but:
   
   - the response had no `Connection: close` header, so a keep-alive client 
(such as the netty-http producer) put the connection back in its pool;
   - the channel was closed right after `writeAndFlush`, without waiting for 
the write to complete.
   
   The next request on the pooled connection then randomly failed with 
`CamelExchangeException: No response received from remote server` (or 
`StacklessClosedChannelException`). This is the cause of the flakiness of 
`NettyHttpSharedSecurityConfigurationTest.testAuthenticationEnforcement`, which 
sends a request answered with 401 and then an authenticated request.
   
   The 401 response now has `Connection: close` and the channel is closed once 
the response is written (`ChannelFutureListener.CLOSE`).
   
   ## Verification
   
   - A temporary loop test (500 times: request answered with 401, then 
authenticated request) failed on `main` in 3 runs out of 3 (a few failures per 
run, with `StacklessClosedChannelException`) and had 0 failure in 3 runs with 
the fix.
   - Added the deterministic test `testUnauthorizedResponseClosesConnection` to 
`NettyHttpSharedSecurityConfigurationTest`: it asserts the `Connection: close` 
header of the 401 response, fails on `main` and passes with the fix.
   
   ## Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   ## Tracking
   
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   ---
   _Bob (IBM) on behalf of apupier_


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