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

Skip to content

Commit 1bc3842

Browse files
committed
fix bug when stream is broken and php_stream_close is used (instead of php_stream_pclose if really wanted).. now leaves it to the stream layer to close a broken connection
1 parent 77a2b73 commit 1bc3842

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

library.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
2121
while(eof) {
2222
if(count++ == 10) { /* too many failures */
2323
if(redis_sock->stream) { /* close stream if still here */
24+
if (!redis_sock->persistent) { /* never ever close persistent streams by ourself */
2425
php_stream_close(redis_sock->stream);
26+
}
2527
redis_sock->stream = NULL;
2628
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
2729
}
2830
zend_throw_exception(redis_exception_ce, "Connection lost", 0 TSRMLS_CC);
2931
return -1;
3032
}
3133
if(redis_sock->stream) { /* close existing stream before reconnecting */
32-
php_stream_close(redis_sock->stream);
34+
if (!redis_sock->persistent) {
35+
php_stream_close(redis_sock->stream);
36+
}
3337
redis_sock->stream = NULL;
3438
}
3539
redis_sock_connect(redis_sock TSRMLS_CC); /* reconnect */
@@ -48,7 +52,9 @@ PHPAPI zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
4852
}
4953

5054
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
51-
php_stream_close(redis_sock->stream);
55+
if (!redis_sock->persistent) {
56+
php_stream_close(redis_sock->stream);
57+
}
5258
redis_sock->stream = NULL;
5359
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
5460
redis_sock->mode = ATOMIC;
@@ -118,7 +124,9 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
118124
}
119125

120126
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
121-
php_stream_close(redis_sock->stream);
127+
if (!redis_sock->persistent) {
128+
php_stream_close(redis_sock->stream);
129+
}
122130
redis_sock->stream = NULL;
123131
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
124132
redis_sock->mode = ATOMIC;
@@ -599,7 +607,9 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
599607
return -1;
600608
}
601609
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
602-
php_stream_close(redis_sock->stream);
610+
if (!redis_sock->persistent) {
611+
php_stream_close(redis_sock->stream);
612+
}
603613
redis_sock->stream = NULL;
604614
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
605615
redis_sock->mode = ATOMIC;
@@ -852,7 +862,9 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
852862
return -1;
853863
}
854864
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
855-
php_stream_close(redis_sock->stream);
865+
if (!redis_sock->persistent) {
866+
php_stream_close(redis_sock->stream);
867+
}
856868
redis_sock->stream = NULL;
857869
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
858870
redis_sock->mode = ATOMIC;
@@ -914,7 +926,9 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
914926
return -1;
915927
}
916928
if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
917-
php_stream_close(redis_sock->stream);
929+
if (!redis_sock->persistent) {
930+
php_stream_close(redis_sock->stream);
931+
}
918932
redis_sock->stream = NULL;
919933
redis_sock->status = REDIS_SOCK_STATUS_FAILED;
920934
redis_sock->mode = ATOMIC;
@@ -976,3 +990,5 @@ PHPAPI void redis_free_socket(RedisSock *redis_sock)
976990
efree(redis_sock);
977991
}
978992

993+
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
994+

0 commit comments

Comments
 (0)