From 02a38501fd2a888dd2041ac49211cb399fa5acaa Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 6 Feb 2025 19:34:30 +0100 Subject: [PATCH] Fix crash in replicationCacheMaster() expecting a nullptr cached_master The replicationCacheMaster() function expects the master pointer to be non-nullptr and the cached_master to be nullptr. But if we happened to get disconnected multiple times and thus also go multiple times through replicationCreateMasterClient(), then we end up with both master and cached_master being non-nullptr, which then triggers an assertion in replicationCacheMaster() which crashes the server. When we are recreating the master struct, mark cached_master for asynchronous freeing, and reset its pointer. Fixes: #849 --- src/replication.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/replication.cpp b/src/replication.cpp index e009731e8..8f3d043d0 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -2343,6 +2343,10 @@ void replicationEmptyDbCallback(void *privdata) { void replicationCreateMasterClient(redisMaster *mi, connection *conn, int dbid) { serverAssert(mi->master == nullptr); mi->master = createClient(conn, serverTL - g_pserver->rgthreadvar); + if (mi->cached_master != nullptr) { + freeClientAsync(mi->cached_master); + mi->cached_master = nullptr; + } if (conn) { serverAssert(connGetPrivateData(mi->master->conn) == mi->master);