Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.2

Bug #26998 Endless loop in write() if connection broken
Submitted: 2020-11-11 19:26 UTC
From: avb Assigned:
Status: Open Package: Net_Socket (version 1.2.2)
PHP Version: Irrelevant OS: Windows
Roadmaps: (Not assigned)    
Subscription  


 [2020-11-11 19:26 UTC] avb (Alexey Borzov)
Description: ------------ write() function has a separate code path for OS_WINDOWS containing a while ($pos < $size) loop. Value returned by fwrite() call within a loop is checked for errors with === false. Unfortunately, as this comment in PHP manual states http://www.php.net/manual/en/function.fwrite.php#96951 fwrite() almost never returns false, it returns 0 in case of errors like broken connection. So the loop never exits. The problem was re-introduced by https://github.com/pear/Net_Socket/pull/3 most likely as this was fixed a waaaaay back in https://pear.php.net/bugs/bug.php?id=14619 Test script: --------------- require_once 'Net/Socket.php'; set_error_handler( function ($errNo, $errStr) { echo $errStr . ' [code: ' . $errNo . "]\r\n"; }, E_ALL & ~E_STRICT & ~E_DEPRECATED ); $suckIt = new Net_Socket(); $suckIt->connect('tcp://localhost', 80); stream_socket_shutdown($suckIt->fp, STREAM_SHUT_WR); echo $suckIt->write("ANYTHING"); Expected result: ---------------- One error saying "write failed" or something Actual result: -------------- Endless barrage of fwrite(): send of 8 bytes failed with errno=10058 A request to send or receive data was disallowed because the socket had already been shut down in that direction with a previous shutdown call. [code: 8]

Comments