From 19550c4819a7d335acd78d43bcd9ca0850cafb52 Mon Sep 17 00:00:00 2001 From: John Sully Date: Wed, 15 Apr 2020 22:26:00 -0400 Subject: [PATCH] Fix race in sendBulk Former-commit-id: 5fd07e08894482e1a55f18ece9c52ff5379b82ec --- src/replication.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/replication.cpp b/src/replication.cpp index bc97773b6..ded3fa01f 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -1228,6 +1228,7 @@ void sendBulkToSlave(connection *conn) { serverAssert(FCorrectThread(replica)); char buf[PROTO_IOBUF_LEN]; ssize_t nwritten, buflen; + std::unique_lock ul(replica->lock); /* Before sending the RDB file, we send the preamble as configured by the * replication process. Currently the preamble is just the bulk count of @@ -3109,6 +3110,10 @@ void roleCommand(client *c) { while ((ln = listNext(&li))) { redisMaster *mi = (redisMaster*)listNodeValue(ln); + std::unique_lock lock; + if (mi->master != nullptr) + lock = std::unique_lock(mi->master->lock); + const char *slavestate = NULL; addReplyArrayLen(c,5); if (g_pserver->fActiveReplica) @@ -3952,6 +3957,13 @@ struct RemoteMasterState { uint64_t mvcc = 0; client *cFake = nullptr; + + ~RemoteMasterState() + { + aeAcquireLock(); + freeClient(cFake); + aeReleaseLock(); + } }; static std::unordered_map g_mapremote;