From 08b03e232218d2adcc2b79d8d48302779079d846 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 4 Sep 2019 17:55:46 +0200 Subject: [PATCH] redis-cli: always report server errors on read errors. Before this commit we may have not consumer buffers when a read error is encountered. Such buffers may contain errors that are important clues for the user: for instance a protocol error in the payload we send in pipe mode will cause the server to abort the connection. If the user does not get the protocol error, debugging what is happening can be a nightmare. This commit fixes issue #3756. --- src/redis-cli.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 1bd419688..480921c0c 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -6073,6 +6073,7 @@ static void pipeMode(void) { /* Handle the readable state: we can read replies from the server. */ if (mask & AE_READABLE) { ssize_t nread; + int read_error = 0; /* Read from socket and feed the hiredis reader. */ do { @@ -6080,7 +6081,8 @@ static void pipeMode(void) { if (nread == -1 && errno != EAGAIN && errno != EINTR) { fprintf(stderr, "Error reading from the server: %s\n", strerror(errno)); - exit(1); + read_error = 1; + break; } if (nread > 0) { redisReaderFeed(reader,ibuf,nread); @@ -6113,6 +6115,11 @@ static void pipeMode(void) { freeReplyObject(reply); } } while(reply); + + /* Abort on read errors. We abort here because it is important + * to consume replies even after a read error: this way we can + * show a potential problem to the user. */ + if (read_error) exit(1); } /* Handle the writable state: we can send protocol to the server. */ -- GitLab