File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments