summaryrefslogtreecommitdiff
path: root/src/replication.c
diff options
context:
space:
mode:
authorEduardo Semprebon <eduardobr@gmail.com>2021-11-09 10:46:10 +0100
committerGitHub <noreply@github.com>2021-11-09 11:46:10 +0200
commitc22d3684bad9bb20825a885ea41a2cc7b30b387c (patch)
treebcbcea6c713eebab258465490eba6e027ac7063c /src/replication.c
parent2ce29e032b6d474c4e819597e1fb690e29e735d6 (diff)
downloadredis-c22d3684bad9bb20825a885ea41a2cc7b30b387c.tar.gz
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.
Diffstat (limited to 'src/replication.c')
-rw-r--r--src/replication.c26
1 files 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