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)
140
140
return -1 ;
141
141
}
142
142
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 ;
143
158
eof = php_stream_eof (redis_sock -> stream );
144
159
for (; eof ; count ++ ) {
145
160
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)
171
186
}
172
187
redis_sock_connect (redis_sock TSRMLS_CC ); /* reconnect */
173
188
if (redis_sock -> stream ) { /* check for EOF again. */
189
+ errno = 0 ;
174
190
eof = php_stream_eof (redis_sock -> stream );
175
191
}
176
192
}
You can’t perform that action at this time.
0 commit comments