8000 Work around PHP bug of liveness checking · jrtkcoder/phpredis@c18d58b · GitHub
[go: up one dir, main page]

Skip to content

Commit c18d58b

Browse files
committed
Work around PHP bug of liveness checking
1 parent 05e38d5 commit c18d58b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

library.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw TSRMLS_DC)
140140
return -1;
141141
}
142142

143+
/* NOITCE: set errno = 0 here
144+
*
145+
* There is a bug in php socket stream to check liveness of a connection:
146+
* if (0 >= recv(sock->socket, &buf, sizeof(buf), MSG_PEEK) && php_socket_errno() != EWOULDBLOCK) {
147+
* alive = 0;
148+
* }
149+
* If last errno is EWOULDBLOCK and recv returns 0 because of connection closed, alive would not be
150+
* set to 0. However, the connection is close indeed. The php_stream_eof is not reliable. This will
151+
* cause a "read error on connection" exception when use a closed persistent connection.
152+
*
153+
* We work around this by set errno = 0 first.
154+
*
155+
* Bug fix of php: https://github.com/php/php-src/pull/1456
156+
* */
157+
errno = 0;
143158
eof = php_stream_eof(redis_sock->stream);
144159
for (; eof; count++) {
145160
if((MULTI == redis_sock->mode) || redis_sock->watching || count == 10) {
@@ -171,6 +186,7 @@ PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw TSRMLS_DC)
171186
}
172187
redis_sock_connect(redis_sock TSRMLS_CC); /* reconnect */
173188
if(redis_sock->stream) { /* check for EOF again. */
189+
errno = 0;
174190
eof = php_stream_eof(redis_sock->stream);
175191
}
176192
}

0 commit comments

Comments
 (0)
0