From: patryk dot szczyglowski at gmail dot com Operating system: Linux 2.6 PHP version: 5.2.8 PHP Bug Type: Sockets related Bug description: socket_read falls into endless loop if remote host disconnects
Description: ------------ When PHP wants to read from a blocking socket when the remote host disconnects, PHP ignores 0 return code from recv() system function and drops into endless loop. Reproduce code: --------------- $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_connect($socket, $ip, $port); // disconnect remote host here $rcv = socket_read($this->socket, 65536, PHP_BINARY_READ); // this line never returns Expected result: ---------------- socket_read returns with FALSE --- php-5.2.8/ext/sockets/sockets.c.orig 2008-10-23 22:21:30.000000000 +0200 +++ php-5.2.8/ext/sockets/sockets.c 2009-01-29 17:32:53.000000000 +0100 @@ -903,6 +903,14 @@ RETURN_FALSE; } + if (retval == 0) { + php_sock->error = errno; + SOCKETS_G(last_error) = errno; + + efree(tmpbuf); + RETURN_FALSE; + } + tmpbuf = erealloc(tmpbuf, retval + 1); tmpbuf[retval] = '\0' ; Actual result: -------------- socket_read never returns, it gets looped in ext/sockets/sockets.c:885 -- Edit bug report at http://bugs.php.net/?id=47289&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47289&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47289&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47289&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47289&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47289&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47289&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47289&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47289&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47289&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47289&r=support Expected behavior: http://bugs.php.net/fix.php?id=47289&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47289&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47289&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47289&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47289&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47289&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47289&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47289&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47289&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47289&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47289&r=mysqlcfg