dmux2313 opened a new issue, #13872:
URL: https://github.com/apache/ignite/issues/13872

   Ignite 2.18.0, on JDK 17+. Found in an application whose thin client refuses 
the retry  of compute tasks, so that a task is never sent twice: after its 
server was restarted, the client never reconnected, and every later 
asynchronous call failed at once.
   
   ## Summary
   
   When an asynchronous request fails with a `ClientConnectionException` and 
the retry policy refuses the retry, the request's future fails and the failed 
channel stays in its holder. The holder creates a new channel only when it has 
none, so every later asynchronous request on that holder takes the same closed 
channel and fails at once with `Channel is closed`, also when the server is 
back. A synchronous request drops the failed channel whatever the policy, and 
the asynchronous requests after it succeed.
   
   A retry policy decides whether a failed request is sent again. It should not 
decide whether the client may connect again for the next request.
   
   ## Steps
   
   `repro.AsyncDeadChannelRepro`, two cases, the client with partition 
awareness off and one address:
   
   1. The retry policy is `ClientRetryNonePolicy`. `getAsync` answers; the 
server node is stopped and a new one started on the same client port with the 
same cache; `getAsync` is called five times, 500 ms apart; then a synchronous 
`get`; then `getAsync` again.
   2. The same with the default policy, `ClientRetryAllPolicy`.
   
   ## Actual
   
   ```
   1. retry policy ClientRetryNonePolicy
      getAsync before the restart: OK, one
      the server restarted on the same port
      getAsync 1 after the restart: FAILED, 
org.apache.ignite.client.ClientConnectionException: Channel is closed 
[remoteAddress=/127.0.0.1:10850]
      getAsync 2 after the restart: FAILED, 
org.apache.ignite.client.ClientConnectionException: Channel is closed 
[remoteAddress=/127.0.0.1:10850]
      getAsync 3 after the restart: FAILED, 
org.apache.ignite.client.ClientConnectionException: Channel is closed 
[remoteAddress=/127.0.0.1:10850]
      getAsync 4 after the restart: FAILED, 
org.apache.ignite.client.ClientConnectionException: Channel is closed 
[remoteAddress=/127.0.0.1:10850]
      getAsync 5 after the restart: FAILED, 
org.apache.ignite.client.ClientConnectionException: Channel is closed 
[remoteAddress=/127.0.0.1:10850]
      get (synchronous): FAILED, 
org.apache.ignite.client.ClientConnectionException: Channel is closed 
[remoteAddress=/127.0.0.1:10850]
      getAsync after the synchronous get: OK, one
   
   2. retry policy ClientRetryAllPolicy (the default)
      getAsync before the restart: OK, one
      the server restarted on the same port
      getAsync 1 after the restart: OK, one
      getAsync 2 after the restart: OK, one
      getAsync 3 after the restart: OK, one
      getAsync 4 after the restart: OK, one
      getAsync 5 after the restart: OK, one
      get (synchronous): OK, one
      getAsync after the synchronous get: OK, one
   ```
   
   ## Expected
   
   In case 1, the first `getAsync` after the restart may fail, since the policy 
refuses its retry. The next ones connect again and answer, as the synchronous 
`get` lets the one after it do.
   
   ## Where it happens
   
   - `ReliableChannel.applyOnClientChannelAsync` 
(`internal/client/thin/ReliableChannel.java`, lines 276–308): on a 
`ClientConnectionException`, when `shouldRetry` is `false`, the future is 
failed and the method returns; the  holder's channel is not closed 
(`onChannelFailure` is called only on the retry branch, line 320).
   - `ClientChannelHolder.getOrCreateChannel` (the same file, line 1148) 
creates a channel only when it has none; it does  not check whether the one it 
has is closed.
   - The synchronous path, `applyOnDefaultChannel`, calls `onChannelFailure` on 
any `ClientConnectionException` before it  consults the policy (line 952), 
which is why one synchronous request heals the holder.
   
   ## Workaround
   
   After a connection error on an asynchronous request, send one synchronous 
request on the same client (any light one, for example 
`IgniteClient.cacheNames()`); its failure, if any, closes the dead channel, and 
the next request connects again. Or use a retry policy that allows the retry, 
where sending a request twice is safe.
   
   
     ## Reproducer
   
     A standalone Maven project, `ignite-core` only. Run with `mvn -q test` 
(JDK 17 or later); about 10 s, on loopback and  in memory.
   
   
[g40-reproducer.zip](https://github.com/user-attachments/files/35283810/g40-reproducer.zip)
   


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