[ 
https://issues.apache.org/jira/browse/THRIFT-1950?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13651266#comment-13651266
 ] 

Travis Beauvais commented on THRIFT-1950:
-----------------------------------------

After further investigation, in the C binding, int he readBytes method, 
buffer_used gets set to 0, so "size_t chunk_size = MIN(len, buffer_used);" sets 
chunk_size to 0 since the minimum between len and buffer_used is 0 but len is 
still 4.
                
> PHP gets stuck in infinite loop
> -------------------------------
>
>                 Key: THRIFT-1950
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1950
>             Project: Thrift
>          Issue Type: Bug
>          Components: PHP - Library
>    Affects Versions: 0.9
>            Reporter: Travis Beauvais
>            Priority: Critical
>
> We have scripts that run continuously and make hundreds of calls to a service 
> using the thrift PHP library. On the receiving side of the request, it 
> occasionally gets stuck in an infinite loop which causes the processes to use 
> up CPU and never die. This doesn't happen 100% of the time and the script 
> will sometimes run for 10 minutes or more before this happens. We run 50 
> instances of the script and I can watch in htop when each one gets stuck. It 
> happens when using the C binding as well as the PHP library. It happens in 
> TTransport.php line 68-77.
>   public function readAll($len) {
>     // return $this->read($len);
>     $data = '';
>     $got = 0;
>     while (($got = TStringFuncFactory::create()->strlen($data)) < $len) {
>       $data .= $this->read($len - $got);
>     }
>     return $data;
>   }
> And in the C binding in php_thrift_protocol.cpp lines 317-330.
>   void readBytes(void* buf, size_t len) {
>     while (len) {
>       size_t chunk_size = MIN(len, buffer_used);
>       if (chunk_size) {
>         memcpy(buf, buffer_ptr, chunk_size);
>         buffer_ptr = reinterpret_cast<char*>(buffer_ptr) + chunk_size;
>         buffer_used -= chunk_size;
>         buf = reinterpret_cast<char*>(buf) + chunk_size;
>         len -= chunk_size;
>       }
>       if (! len) break;
>       refill();
>     }
>   }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to