Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
0.13.0
-
None
Description
PHP returns 0 for fwrite calls when the socket has been reset by peer.
Currently the write code looks like this:
while (TStringFuncFactory::create()->strlen($buf) > 0) { $writable = @stream_select( $null, $write, $null, $this->sendTimeoutSec_, $this->sendTimeoutUsec_ ); if ($writable > 0) { <--- peer connection closed makes socket writable $written = fwrite($this->handle_, $buf); <-- this will return 0 if ($written === -1 || $written === false) { <--- we skip this because we got 0 not false } $buf = TStringFuncFactory::create()->substr($buf, $written); <--- buf still same } else { ... }
There needs to be a check for the combination of $written === 0 and feof($this->handle_) to detect connections closed by peer.
This still isn't perfect in the case where the peer decides to send something back on the socket before closing (the socket wouldn't get marked as feof until something is read as well), but that would be a violation of the thrift protocol as I understand it.
Attachments
Issue Links
- links to