Commit 12c56a8e authored by antirez's avatar antirez
Browse files

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.
parent f7090f43
...@@ -6724,6 +6724,7 @@ static void pipeMode(void) { ...@@ -6724,6 +6724,7 @@ static void pipeMode(void) {
/* Handle the readable state: we can read replies from the server. */ /* Handle the readable state: we can read replies from the server. */
if (mask & AE_READABLE) { if (mask & AE_READABLE) {
ssize_t nread; ssize_t nread;
int read_error = 0;
/* Read from socket and feed the hiredis reader. */ /* Read from socket and feed the hiredis reader. */
do { do {
...@@ -6731,7 +6732,8 @@ static void pipeMode(void) { ...@@ -6731,7 +6732,8 @@ static void pipeMode(void) {
if (nread == -1 && errno != EAGAIN && errno != EINTR) { if (nread == -1 && errno != EAGAIN && errno != EINTR) {
fprintf(stderr, "Error reading from the server: %s\n", fprintf(stderr, "Error reading from the server: %s\n",
strerror(errno)); strerror(errno));
exit(1); read_error = 1;
break;
} }
if (nread > 0) { if (nread > 0) {
redisReaderFeed(reader,ibuf,nread); redisReaderFeed(reader,ibuf,nread);
...@@ -6764,6 +6766,11 @@ static void pipeMode(void) { ...@@ -6764,6 +6766,11 @@ static void pipeMode(void) {
freeReplyObject(reply); freeReplyObject(reply);
} }
} while(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. */ /* Handle the writable state: we can send protocol to the server. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment