From c22d3684bad9bb20825a885ea41a2cc7b30b387c Mon Sep 17 00:00:00 2001 From: Eduardo Semprebon Date: Tue, 9 Nov 2021 10:46:10 +0100 Subject: [PATCH] Fix diskless load handling on broken EOF marker (#9752) During diskless replication, the check for broken EOF mark is misplaced and should be earlier. Now we do not swap db, we do proper cleanup and correctly raise module events on this kind of failure. This issue existed prior to #9323, but before, the side effect was not restoring backup and not raising the correct module events on this failure. --- src/replication.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/replication.c b/src/replication.c index 6c79d72d8..0f2512fcb 100644 --- a/src/replication.c +++ b/src/replication.c @@ -1963,11 +1963,24 @@ void readSyncBulkPayload(connection *conn) { connRecvTimeout(conn, server.repl_timeout*1000); startLoading(server.repl_transfer_size, RDBFLAGS_REPLICATION, asyncLoading); + int loadingFailed = 0; if (rdbLoadRio(&rdb,RDBFLAGS_REPLICATION,&rsi,dbarray) != C_OK) { /* RDB loading failed. */ serverLog(LL_WARNING, "Failed trying to load the MASTER synchronization DB " "from socket: %s", strerror(errno)); + loadingFailed = 1; + } else if (usemark) { + /* Verify the end mark is correct. */ + if (!rioRead(&rdb, buf, CONFIG_RUN_ID_SIZE) || + memcmp(buf, eofmark, CONFIG_RUN_ID_SIZE) != 0) + { + serverLog(LL_WARNING, "Replication stream EOF marker is broken"); + loadingFailed = 1; + } + } + + if (loadingFailed) { stopLoading(0); cancelReplicationHandshake(1); rioFreeConn(&rdb, NULL); @@ -2013,19 +2026,6 @@ void readSyncBulkPayload(connection *conn) { /* Inform about db change, as replication was diskless and didn't cause a save. */ server.dirty++; - /* Verify the end mark is correct. */ - if (usemark) { - if (!rioRead(&rdb,buf,CONFIG_RUN_ID_SIZE) || - memcmp(buf,eofmark,CONFIG_RUN_ID_SIZE) != 0) - { - stopLoading(0); - serverLog(LL_WARNING,"Replication stream EOF marker is broken"); - cancelReplicationHandshake(1); - rioFreeConn(&rdb, NULL); - return; - } - } - stopLoading(1); /* Cleanup and restore the socket to the original state to continue