Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a269ab

Browse files
committed
Don't allow reconnect on read response
1 parent 79313e7 commit 5a269ab

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

cluster_library.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ static int cluster_check_response(redisCluster *c, REDIS_REPLY_TYPE *reply_type)
11611161
CLUSTER_CLEAR_ERROR(c);
11621162
CLUSTER_CLEAR_REPLY(c);
11631163

1164-
if (-1 == redis_check_eof(c->cmd_sock, 1) ||
1164+
if (-1 == redis_check_eof(c->cmd_sock, 1, 1) ||
11651165
EOF == (*reply_type = php_stream_getc(c->cmd_sock->stream)))
11661166
{
11671167
return -1;

cluster_library.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@
6262

6363
/* Protected sending of data down the wire to a RedisSock->stream */
6464
#define CLUSTER_SEND_PAYLOAD(sock, buf, len) \
65-
(sock && !redis_sock_server_open(sock) && sock->stream && !redis_check_eof(sock, 1 ) && \
65+
(sock && !redis_sock_server_open(sock) && sock->stream && !redis_check_eof(sock, 0, 1) && \
6666
php_stream_write(sock->stream, buf, len)==len)
6767

6868
/* Macro to read our reply type character */
6969
#define CLUSTER_VALIDATE_REPLY_TYPE(sock, type) \
70-
(redis_check_eof(sock, 1) == 0 && \
70+
(redis_check_eof(sock, 1, 1) == 0 && \
7171
(php_stream_getc(sock->stream) == type))
7272

7373
/* Reset our last single line reply buffer and length */

library.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ redis_error_throw(RedisSock *redis_sock)
287287
}
288288

289289
PHP_REDIS_API int
290-
redis_check_eof(RedisSock *redis_sock, int no_throw)
290+
redis_check_eof(RedisSock *redis_sock, zend_bool no_retry, zend_bool no_throw)
291291
{
292292
unsigned int retry_index;
293293
char *errmsg;
@@ -322,7 +322,7 @@ redis_check_eof(RedisSock *redis_sock, int no_throw)
322322
} else {
323323
errmsg = "Connection lost";
324324
redis_backoff_reset(&redis_sock->backoff);
325-
for (retry_index = 0; retry_index < redis_sock->max_retries; ++retry_index) {
325+
for (retry_index = 0; !no_retry && retry_index < redis_sock->max_retries; ++retry_index) {
326326
/* close existing stream before reconnecting */
327327
if (redis_sock->stream) {
328328
redis_sock_disconnect(redis_sock, 1);
@@ -592,7 +592,7 @@ redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes)
592592
char *reply;
593593
size_t got;
594594

595-
if (-1 == bytes || -1 == redis_check_eof(redis_sock, 0)) {
595+
if (-1 == bytes || -1 == redis_check_eof(redis_sock, 1, 0)) {
596596
return NULL;
597597
}
598598

@@ -2865,7 +2865,7 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
28652865
PHP_REDIS_API int
28662866
redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz)
28672867
{
2868-
if (redis_check_eof(redis_sock, 0) == 0 &&
2868+
if (redis_check_eof(redis_sock, 0, 0) == 0 &&
28692869
php_stream_write(redis_sock->stream, cmd, sz) == sz
28702870
) {
28712871
return sz;
@@ -3343,7 +3343,7 @@ redis_sock_gets(RedisSock *redis_sock, char *buf, int buf_size,
33433343
size_t *line_size)
33443344
{
33453345
// Handle EOF
3346-
if(-1 == redis_check_eof(redis_sock, 0)) {
3346+
if(-1 == redis_check_eof(redis_sock, 1, 0)) {
33473347
return -1;
33483348
}
33493349

@@ -3376,7 +3376,7 @@ redis_read_reply_type(RedisSock *redis_sock, REDIS_REPLY_TYPE *reply_type,
33763376
long *reply_info)
33773377
{
33783378
// Make sure we haven't lost the connection, even trying to reconnect
3379-
if(-1 == redis_check_eof(redis_sock, 0)) {
3379+
if(-1 == redis_check_eof(redis_sock, 1, 0)) {
33803380
// Failure
33813381
*reply_type = EOF;
33823382
return -1;

library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ PHP_REDIS_API int redis_unsubscribe_response(INTERNAL_FUNCTION_PARAMETERS,
111111
RedisSock *redis_sock, zval *z_tab, void *ctx);
112112

113113
PHP_REDIS_API int redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz);
114-
PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw);
114+
PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, zend_bool no_retry, zend_bool no_throw);
115115
PHP_REDIS_API RedisSock *redis_sock_get(zval *id, int nothrow);
116116
PHP_REDIS_API void redis_free_socket(RedisSock *redis_sock);
117117
PHP_REDIS_API void redis_sock_set_err(RedisSock *redis_sock, const char *msg, int msg_len);

0 commit comments

Comments
 (0)