THRIFT-5777: python fix mismatched timeout exceptions. #2961
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What error occurred?
When the Python client times out while reading content from the server, the exception thrown is not "read timeout," but rather "unexpected exception."
Why did this error occur?
the socket.timeout error doesn't includes the errno parameter in its args attribute.
I try to make a timeout error on my pc, it only contains the error string.
And my system is ubuntu 22.04
TSocket.read handle exception error
Because
socket.error.args == ('timed out',)
, the conditionelif e.args[0] == errno.ETIMEDOUT
cannot be True, resulting in the throwing of the wrong exceptionTTransportException(message="unexpected exception", inner=e)
.How to fix it
I determine whether a timeout has occurred by checking if the exception is a socket.timeout, no longer relying on e.args.
[skip ci]
anywhere in the commit message to free up build resources.