summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Parry <nparry@gmail.com>2013-01-17 23:55:43 -0500
committerantirez <antirez@gmail.com>2013-01-18 11:49:58 +0100
commit0f4dbd9a11f34306638c86f55fbb2f9ba6db8f54 (patch)
treee37940091867a11f578de55c5daca6c45b9d8f87
parent21159d53f58b01dfcd5e2451b617da0f3645aedb (diff)
downloadredis-0f4dbd9a11f34306638c86f55fbb2f9ba6db8f54.tar.gz
redis-cli --rdb fails if server sends a ping
Redis pings slaves in "pre-synchronization stage" with newlines. (See https://github.com/antirez/redis/blob/2.6.9/src/replication.c#L814) However, redis-cli does not expect this - it sees the newline as the end of the bulk length line, and ends up returning 0 as bulk the length. This manifests as the following when running redis-cli: $ ./src/redis-cli --rdb some_file SYNC sent to master, writing 0 bytes to 'some_file' Transfer finished with success. With this commit, we just ignore leading newlines while reading the bulk length line. To reproduce the problem, load enough data into Redis so that the preparation of the RDB snapshot takes long enough for a ping to occur while redis-cli is waiting for the data.
-rw-r--r--src/redis-cli.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/redis-cli.c b/src/redis-cli.c
index c3938636b..0bc61bb25 100644
--- a/src/redis-cli.c
+++ b/src/redis-cli.c
@@ -958,8 +958,8 @@ unsigned long long sendSync(int fd) {
fprintf(stderr,"Error reading bulk length while SYNCing\n");
exit(1);
}
- if (*p == '\n') break;
- p++;
+ if (*p == '\n' && p != buf) break;
+ if (*p != '\n') p++;
}
*p = '\0';
if (buf[0] == '-') {