You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix deferred freeClient clobbering replication state after replicaof
Since PR #3324, freeClient() on a primary client with pending IO is
deferred via freeClientAsync. The deferred free eventually chains through
replicationCachePrimary() -> replicationHandlePrimaryDisconnection(),
which unconditionally set repl_state = REPL_STATE_CONNECT.
This causes two bugs:
1. REPLICAOF NO ONE: primary_host is NULL when the deferred free runs,
so replicationCron calls connectWithPrimary(NULL) -> SIGSEGV in
connTLSConnect (inet_pton with NULL addr).
2. REPLICAOF newhost newport: the deferred free clobbers the already-
progressed repl_state (CONNECTING) back to CONNECT, causing
replicationCron to call connectWithPrimary() again, which overwrites
server.repl_transfer_s without closing the previous connection (FD leak).
Fix by making replicationHandlePrimaryDisconnection() only transition to
REPL_STATE_CONNECT when repl_state is still REPL_STATE_CONNECTED (meaning
this is a genuine disconnect, not a stale deferred free). If repl_state
has already moved on, the deferred free is stale and should not mutate
the state machine.
Additionally:
- Add NULL check for addr in connTLSConnect() as defense in depth.
- Add 10s timeout to the WAITAOF test to prevent indefinite hanging.
- Add dedicated tests for the repoint scenario.
Signed-off-by: Yaron Sananes <yaron.sananes@gmail.com>
0 commit comments