-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in writing to socket is not handled. #115
Comments
This happens usually when the Broker drops the connection on purpose and for good reason. Returning a false is not useful because this is called from many different places, and it is very inconvenient to recover from there. Reconnecting(warm) in this function is not practical either because the Broker will only drop the connection again. |
I can only spot two places where _fwrite is called. In other places the normal fwrite is called. Not sure why this difference is made here. I agree that some error checking (/throwing) needs to be done. Where the issue is eventually resolved is irrelevant to this issue at this moment in my oppinion. In my case (following the example code) the broken pipe error is detected but ignored and propagates, resulting in an endless loop. |
The problem actual occurs at fwrite() not just $this->_fwrite(). The false is returned when fwrite() face the condition: invalid stream ID, physical connection error, connection closure by local or remote peer. There are 7 fwrite()s in the code at the moment, and that will grow when(if?) the code is enhanced to support the other packet types. All the fwrite()s need to be protected because we don't know when the errors will come. class AppException extends \Exception { |
In my case, I was repeatedly confronted with error message "php fwrite(): send of 8192 bytes failed with errno=11" while the client was trying to write LARGE size file (a json about 200KB) into the tcp socket. errno 11 indicates the tcp connection which fwrite() being writing is not available. What is interesting is fwrite() will re-try to write to the tcp until the socket is ready (or timeout). So I guess all this is caused by the Non-blocking mode that set in code line Line 159 in 7a9d6b2
I just modify this line to set the socket stream to be in blocking mode With the blocking mode, the fwrite() loops writes to the tcp socket after socket is ready. So errno 11 is solved. |
When the fwrite on line 435 failes, the 'return false' is unhandled. (no call to _fwrite handles the return value)
In my case i had a 'broken pipe' socket error, resulting in an endless loop.
The text was updated successfully, but these errors were encountered: