Ivan Andika created RATIS-2848:
----------------------------------

             Summary: NettyClient close during connect can fail or attempt to 
reopen a closed client
                 Key: RATIS-2848
                 URL: https://issues.apache.org/jira/browse/RATIS-2848
             Project: Ratis
          Issue Type: Bug
          Components: Netty
            Reporter: Ivan Andika
            Assignee: Ivan Andika


An inbound Netty exception can close a client while `connect()` is still 
completing. The integration CI's leader-kill scenario exposed an 
`IllegalStateException` instead of the normal connection-failure/retry behavior.

This is a production transport race found while fixing integration CI. 
h2. Deterministic reproduction

1. Start `NettyClient.connect()` on a worker thread.
2. Install an outbound handler that leaves the connect promise pending without 
blocking the event loop.
3. Close the client on its event loop, matching the inbound-exception callback 
path.
4. Release the pending connect.
5. Check the close/connect results, channel closure and subsequent writes.

The original implementation could dereference a null channel during close, 
attempt the invalid `CLOSED -> RUNNING` startup transition, or leave the 
late-published channel open.
h2. Expected behavior

Closing a connecting client must be safe and terminal. Once closed, the client 
must not become writable again; the connecting channel must be closed; and 
startup failure must not overwrite the closed lifecycle state.
h2. Root cause

The channel was assigned only after waiting for the connect future. A 
concurrent close therefore could not see the connecting channel. The generic 
startup transition then attempted to enter `RUNNING` regardless of whether a 
concurrent close had already completed.
h2. Proposed fix

Publish the connecting channel before waiting, with visibility to concurrent 
close. Close a late-published channel if the client is already closing/closed. 
Transition to `RUNNING` or startup-failure states only while still `STARTING`, 
and allow closing before channel publication without dereferencing null.

 



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to