Fix replication lseek check (#14135)

In `sendBulkToSlave`, the `lseek()` call used to position the RDB file
descriptor before reading the next data chunk was not checked for
errors.
If the `lseek()` system call were to fail, the file descriptor would
remain at an incorrect position. The subsequent `read()` would then
fetch the wrong data, leading to a corrupted RDB stream being sent to
the replica. This could cause the replication to fail or result in data
inconsistency.
This patch introduces a check for the `lseek()` return value. On
failure, it logs a detailed warning and aborts the replication by
freeing the client, mirroring the existing error handling for `read()`
and `write()` calls within the same function. This improves the
robustness of the RDB transfer process.

---------

Co-authored-by: Yuan Wang <wangyuancode@163.com>
This commit is contained in:
Yi Deng 2025-06-27 09:07:33 +08:00 committed by GitHub
parent 8948a5d2b2
commit 531b82df22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 1 deletions

View File

@ -1574,7 +1574,12 @@ void sendBulkToSlave(connection *conn) {
}
/* If the preamble was already transferred, send the RDB bulk data. */
lseek(slave->repldbfd,slave->repldboff,SEEK_SET);
if (lseek(slave->repldbfd,slave->repldboff,SEEK_SET) == -1) {
serverLog(LL_WARNING,"Failed to lseek the RDB file to offset %lld for replica %s: %s",
(long long)slave->repldboff, replicationGetSlaveName(slave), strerror(errno));
freeClient(slave);
return;
}
buflen = read(slave->repldbfd,buf,PROTO_IOBUF_LEN);
if (buflen <= 0) {
serverLog(LL_WARNING,"Read error sending DB to replica: %s",