@@ -1419,8 +1419,11 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char
14191419 return -1 ;
14201420 }
14211421
1422- /* Now check the response from the node we queried. */
1422+ /* Check response and short-circuit on success or communication error */
14231423 resp = cluster_check_response (c , & c -> reply_type TSRMLS_CC );
1424+ if (resp == 0 || resp == -1 ) {
1425+ break ;
1426+ }
14241427
14251428 /* Handle MOVED or ASKING redirection */
14261429 if (resp == 1 ) {
@@ -1439,22 +1442,28 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char
14391442 }
14401443 }
14411444
1442- /* We're timed out if cluster_check_response returned -1, or if the
1443- * response was non-zero and we've been in the loop too long */
1444- timedout = resp == -1 || (resp && c -> waitms ? mstime () - msstart >= c -> waitms : 0 );
1445- } while (resp != 0 && !c -> clusterdown && !timedout );
1445+ /* See if we've timed out in the command loop */
1446+ timedout = c -> waitms ? mstime () - msstart >= c -> waitms : 0 ;
1447+ } while (!c -> clusterdown && !timedout );
14461448
14471449 // If we've detected the cluster is down, throw an exception
14481450 if (c -> clusterdown ) {
14491451 zend_throw_exception (redis_cluster_exception_ce ,
14501452 "The Redis Cluster is down (CLUSTERDOWN)" , 0 TSRMLS_CC );
14511453 return -1 ;
1452- } else if (timedout ) {
1454+ } else if (timedout || resp == -1 ) {
14531455 // Make sure the socket is reconnected, it such that it is in a clean state
14541456 redis_sock_disconnect (c -> cmd_sock , 1 TSRMLS_CC );
14551457
1456- zend_throw_exception (redis_cluster_exception_ce ,
1457- "Timed out attempting to find data in the correct node!" , 0 TSRMLS_CC );
1458+ if (timedout ) {
1459+ zend_throw_exception (redis_cluster_exception_ce ,
1460+ "Timed out attempting to find data in the correct node!" , 0 TSRMLS_CC );
1461+ } else {
1462+ zend_throw_exception (redis_cluster_exception_ce ,
1463+ "Error processing response from Redis node!" , 0 TSRMLS_CC );
1464+ }
1465+
1466+ return -1 ;
14581467 }
14591468
14601469 /* Clear redirection flag */
0 commit comments