From 4a0e20bbc91da1e776c619df741e0e9377193602 Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 1 Dec 2025 10:20:32 +0800 Subject: [PATCH] Handle failed psync log when there is no replication backlog (#2886) This crash was introduced in #2877, we will crash when there is no replication backlog. Signed-off-by: Binbin --- src/replication.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/replication.c b/src/replication.c index 5e8b7068f..403662522 100644 --- a/src/replication.c +++ b/src/replication.c @@ -862,11 +862,17 @@ int primaryTryPartialResynchronization(client *c, long long psync_offset) { /* We still have the data our replica is asking for? */ if (!server.repl_backlog || psync_offset < server.repl_backlog->offset || psync_offset > (server.repl_backlog->offset + server.repl_backlog->histlen)) { - serverLog(LL_NOTICE, - "Unable to partial resync with replica %s for lack of backlog (Replica request was %s:%lld, " - "and I can only reply with the range [%lld, %lld]).", - replicationGetReplicaName(c), primary_replid, psync_offset, server.repl_backlog->offset, - server.repl_backlog->offset + server.repl_backlog->histlen); + if (!server.repl_backlog) { + serverLog(LL_NOTICE, + "Unable to partial resync with replica %s for lack of backlog (Replica request was: %s:%lld).", + replicationGetReplicaName(c), primary_replid, psync_offset); + } else { + serverLog(LL_NOTICE, + "Unable to partial resync with replica %s for lack of backlog (Replica request was %s:%lld, " + "and I can only reply with the range [%lld, %lld]).", + replicationGetReplicaName(c), primary_replid, psync_offset, server.repl_backlog->offset, + server.repl_backlog->offset + server.repl_backlog->histlen); + } if (psync_offset > server.primary_repl_offset) { serverLog(LL_WARNING, "Warning: replica %s tried to PSYNC with an offset (%lld) that is greater than "