From 5edc61dfd57523fe577452a54e620da63da4594d Mon Sep 17 00:00:00 2001 From: John Sully Date: Tue, 2 Apr 2019 22:32:10 -0400 Subject: [PATCH] Cluster tests shouldn't crash (note: still not passing either) Former-commit-id: e63b2880b050d64849daf17d81cd0d4cabf2277a --- src/cluster.c | 8 ++++++-- src/replication.cpp | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index e4b5464e1..e4b5d4dc5 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -79,7 +79,9 @@ void moduleCallClusterReceivers(const char *sender_id, uint64_t module_id, uint8 struct redisMaster *getFirstMaster() { - serverAssert(listLength(server.masters) == 1); + serverAssert(listLength(server.masters) <= 1); + if (!listLength(server.masters)) + return NULL; return listFirst(server.masters)->value; } @@ -3578,7 +3580,9 @@ void clusterCron(void) { myself->slaveof && nodeHasAddr(myself->slaveof)) { - replicationUnsetMaster(getFirstMaster()); + struct redisMaster *mi = getFirstMaster(); + if (mi != NULL) + replicationUnsetMaster(mi); replicationAddMaster(myself->slaveof->ip, myself->slaveof->port); } diff --git a/src/replication.cpp b/src/replication.cpp index 59e80652e..a5e3fdda0 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -2796,7 +2796,7 @@ void processClientsWaitingReplicas(void) { long long replicationGetSlaveOffset(redisMaster *mi) { long long offset = 0; - if (mi->masterhost != NULL) { + if (mi != NULL && mi->masterhost != NULL) { if (mi->master) { offset = mi->master->reploff; } else if (mi->cached_master) {