diff options
author | michael-grunder <michael.grunder@gmail.com> | 2018-10-17 07:31:52 +0300 |
---|---|---|
committer | michael-grunder <michael.grunder@gmail.com> | 2018-10-17 07:31:52 +0300 |
commit | 07ef7f4e6599e42a5d92f6a1bca5e45290dd745c (patch) | |
tree | 2d2f40b4370bc759c0429df16585d4a83ec72b46 /cluster_library.c | |
parent | 27df92208a6a7c712ae08407a430059ab8b0d1ad (diff) |
Make our timeout or response error handling more explicit.
Although a -1 return value from cluster_check_response is likely
a timeout, it is not the only possibility, so handle the loop
timeout and error response in distinct ways.
Diffstat (limited to 'cluster_library.c')
-rw-r--r-- | cluster_library.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/cluster_library.c b/cluster_library.c index 4c785703..2d0cc996 100644 --- a/cluster_library.c +++ b/cluster_library.c @@ -1419,8 +1419,11 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char return -1; } - /* Now check the response from the node we queried. */ + /* Check response and short-circuit on success or communication error */ resp = cluster_check_response(c, &c->reply_type TSRMLS_CC); + if (resp == 0 || resp == -1) { + break; + } /* Handle MOVED or ASKING redirection */ if (resp == 1) { @@ -1439,22 +1442,28 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char } } - /* We're timed out if cluster_check_response returned -1, or if the - * response was non-zero and we've been in the loop too long */ - timedout = resp == -1 || (resp && c->waitms ? mstime() - msstart >= c->waitms : 0); - } while (resp != 0 && !c->clusterdown && !timedout); + /* See if we've timed out in the command loop */ + timedout = c->waitms ? mstime() - msstart >= c->waitms : 0; + } while (!c->clusterdown && !timedout); // If we've detected the cluster is down, throw an exception if (c->clusterdown) { zend_throw_exception(redis_cluster_exception_ce, "The Redis Cluster is down (CLUSTERDOWN)", 0 TSRMLS_CC); return -1; - } else if (timedout) { + } else if (timedout || resp == -1) { // Make sure the socket is reconnected, it such that it is in a clean state redis_sock_disconnect(c->cmd_sock, 1 TSRMLS_CC); - zend_throw_exception(redis_cluster_exception_ce, - "Timed out attempting to find data in the correct node!", 0 TSRMLS_CC); + if (timedout) { + zend_throw_exception(redis_cluster_exception_ce, + "Timed out attempting to find data in the correct node!", 0 TSRMLS_CC); + } else { + zend_throw_exception(redis_cluster_exception_ce, + "Error processing response from Redis node!", 0 TSRMLS_CC); + } + + return -1; } /* Clear redirection flag */ |