shinseongsu opened a new pull request, #950:
URL: https://github.com/apache/httpcomponents-client/pull/950

   Follow-up to #943.
   
   Once the socket is connected, the future returned by `connect()` still has 
the session request as its dependency, and that request is already done. So 
cancelling during the TLS handshake doesn't touch the session: it stays open 
until the handshake times out. If the handshake finishes after the cancel, 
`future.completed()` is ignored and the connection is left open with nothing 
holding it. It isn't in the pool and doesn't show up in the pool stats.
   
   The change registers a dependency that closes the connection right before 
the handshake starts. The session request goes through a `ComplexCancellable` 
holder, like in #943, so a connect that completes before 
`sessionRequester.connect()` returns can't overwrite it.
   
   ### How I tested it
   
   Pooling async client, max 20 per route, 20 s connect timeout, against a 
local TLS server that accepts the TCP connection and then holds the handshake. 
20 requests, each cancelled after 300 ms. Client sockets counted with `lsof` 3 
s after the last cancel (the count includes one probe request).
   
   | server handshake | master | patched |
   |---|---|---|
   | never answers | 21 ESTABLISHED | 1 |
   | answers after 1 s | 21 ESTABLISHED, pool stats show 0 leased / 0 available 
| 1 |
   
   On master the server sees the cancelled connections close only when the 
client is shut down. With the change each one is reset about 0.3 s after it was 
accepted.
   
   
`DefaultAsyncClientConnectionOperatorTest#testCancelDuringTlsHandshakeClosesSession`
 fails on master and passes with the change. httpclient5 `verify`: 1161 tests, 
0 failures. httpclient5-testing async tests: 407, 0 failures.
   
   The connection is closed with `CloseMode.IMMEDIATE`, so the server gets an 
RST rather than a close_notify. That seemed right for a handshake that never 
finished, but let me know if you'd rather have GRACEFUL here.
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to