Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5199

Infinite loop in PHP TSocket::write when peer closes connection

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 0.13.0
    • 0.14.0
    • PHP - Library
    • 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

          Activity

            People

              Heilig Tim
              Heilig Tim
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1.5h
                  1.5h