Tim created THRIFT-5199:
---------------------------
Summary: Infinite loop in PHP TSocket::write when peer closes
connection
Key: THRIFT-5199
URL: https://issues.apache.org/jira/browse/THRIFT-5199
Project: Thrift
Issue Type: Bug
Components: PHP - Library
Affects Versions: 0.13.0
Reporter: Tim
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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)