diff --git a/src/cluster.cpp b/src/cluster.cpp index 99af97594..7f6d897c9 100644 --- a/src/cluster.cpp +++ b/src/cluster.cpp @@ -771,7 +771,7 @@ unsigned long getClusterConnectionsCount(void) { /* We decrement the number of nodes by one, since there is the * "myself" node too in the list. Each node uses two file descriptors, * one incoming and one outgoing, thus the multiplication by 2. */ - return g_pserver->cluster_enabled ? + return g_pserver->cluster_enabled && g_pserver->cluster != nullptr ? ((dictSize(g_pserver->cluster->nodes)-1)*2) : 0; } diff --git a/src/replication.cpp b/src/replication.cpp index 3b8b6f9e1..44ab62992 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -2977,6 +2977,7 @@ error: } void readSyncBulkPayload(connection *conn) { + serverAssert(GlobalLocksAcquired()); rdbSaveInfo rsi; redisMaster *mi = (redisMaster*)connGetPrivateData(conn); static int usemark = 0; @@ -2993,6 +2994,9 @@ void readSyncBulkPayload(connection *conn) { return; } + if (conn != mi->repl_transfer_s) + return; + /* Final setup of the connected slave <- master link */ replicationCreateMasterClient(mi,mi->repl_transfer_s,rsi.repl_stream_db); if (mi->isRocksdbSnapshotRepl) { @@ -3801,12 +3805,14 @@ int connectWithMaster(redisMaster *mi) { * Never call this function directly, use cancelReplicationHandshake() instead. */ void undoConnectWithMaster(redisMaster *mi) { + serverAssert(GlobalLocksAcquired()); auto conn = mi->repl_transfer_s; connSetPrivateData(conn, nullptr); - aePostFunction(g_pserver->rgthreadvar[mi->ielReplTransfer].el, [conn]{ - connClose(conn); - }); mi->repl_transfer_s = NULL; + int result = aePostFunction(g_pserver->rgthreadvar[mi->ielReplTransfer].el, [conn]{ + connClose(conn); + }, false); + serverAssert(result == AE_OK); } /* Abort the async download of the bulk dataset while SYNC-ing with master. @@ -3961,6 +3967,10 @@ void freeMasterInfo(redisMaster *mi) { sdsfree(mi->masterauth); zfree(mi->masteruser); + if (g_pserver->rdb_filename != nullptr && g_pserver->rdb_filename == mi->repl_transfer_tmpfile) { + unlink(g_pserver->rdb_filename); + g_pserver->rdb_filename = nullptr; + } if (mi->repl_transfer_tmpfile) zfree(mi->repl_transfer_tmpfile); delete mi->staleKeyMap;