Permalink
Browse files

CLOSE_WAIT fix.

  • Loading branch information...
1 parent da074dd commit e0b5c6387f3840cc81aa872aecd54c18071cf4a6 @nicolasff nicolasff committed Oct 29, 2010
Showing with 11 additions and 4 deletions.
  1. +11 −4 library.c
View
@@ -10,13 +10,20 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
int eof = php_stream_eof(redis_sock->stream);
int count = 0;
while(eof) {
- if(count++ == 10) {
+ if(count++ == 10) { /* too many failures */
+ if(redis_sock->stream) { /* close stream if still here */
+ php_stream_close(redis_sock->stream);
+ redis_sock->stream = NULL;
+ }
zend_throw_exception(redis_exception_ce, "Connection lost", 0 TSRMLS_CC);
return -1;
}
- redis_sock->stream = NULL;
- redis_sock_connect(redis_sock TSRMLS_CC);
- if(redis_sock->stream) {
+ if(redis_sock->stream) { /* close existing stream before reconnecting */
+ php_stream_close(redis_sock->stream);
+ redis_sock->stream = NULL;
+ }
+ redis_sock_connect(redis_sock TSRMLS_CC); /* reconnect */
+ if(redis_sock->stream) { /* check for EOF again. */
eof = php_stream_eof(redis_sock->stream);
}
}

0 comments on commit e0b5c63

Please sign in to comment.