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

TBufferedTransport doesn't clear it's buffer on a failed flush call

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.9.1
    • 0.9.2
    • PHP - Library
    • Patch Available

    Description

      On flush in the php implementation of the TBufferedTransport it doesn't clear the internal buffer before calling the underlying write function. However the write function in TBufferedTransport does.

      TBufferedTransport.php
        public function write($buf) {
          $this->wBuf_ .= $buf;
          if (TStringFuncFactory::create()->strlen($this->wBuf_) >= $this->wBufSize_) {
            $out = $this->wBuf_;
      
            // Note that we clear the internal wBuf_ prior to the underlying write
            // to ensure we're in a sane state (i.e. internal buffer cleaned)
            // if the underlying write throws up an exception
            $this->wBuf_ = '';
            $this->transport_->write($out);
          }
        }
      
        public function flush() {
          if (TStringFuncFactory::create()->strlen($this->wBuf_) > 0) {
            $this->transport_->write($this->wBuf_);
            $this->wBuf_ = '';
          }
          $this->transport_->flush();
        }
      

      If a write on the underlying transport fails when we call flush, the internal buffer won't be cleared.
      This causes some interesting issues when this happens. If you happen to call the same function twice (first call fails to write, but the second one succeeds), it will call the function on the server with the data provided in the first call, rather than your current call.

      Attachments

        Activity

          People

            jensg Jens Geyer
            solarnz Chris Trotman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: