You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jens Geyer (Jira)" <ji...@apache.org> on 2020/05/13 21:53:00 UTC

[jira] [Resolved] (THRIFT-5199) Infinite loop in PHP TSocket::write when peer closes connection

     [ https://issues.apache.org/jira/browse/THRIFT-5199?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jens Geyer resolved THRIFT-5199.
--------------------------------
    Fix Version/s: 0.14.0
       Resolution: Fixed

> 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
>            Assignee: Tim
>            Priority: Critical
>             Fix For: 0.14.0
>
>          Time Spent: 1.5h
>  Remaining Estimate: 0h
>
> PHP returns 0 for fwrite calls when the socket has been reset by peer.
>  
> Currently the write code looks like this:
> {code}
> 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 { ... } 
> {code}
> 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)