Skip to content
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

THRIFT-5777: python fix mismatched timeout exceptions. #2961

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bwangelme
Copy link
Contributor

@bwangelme bwangelme commented Apr 15, 2024

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.

Python 3.11.1 (main, Jan  5 2023, 14:25:08) [GCC 11.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.13.2 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import socket
   ...: from urllib.request import urlopen
   ...:
   ...: url = 'http://httpbin.org/get'
   ...:
   ...: socket.setdefaulttimeout(0.01)
   ...: try:
   ...:     urlopen(url)
   ...: except Exception as e:
   ...:     err1 = e.reason
   ...:
   ...:

In [2]: type(err1)
Out[2]: TimeoutError

In [3]: err1.args
Out[3]: ('timed out',)

And my system is ubuntu 22.04

ø> uname -a
Linux Macmini 6.2.0-36-generic #37~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct  9 15:34:04 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

TSocket.read handle exception error

Because socket.error.args == ('timed out',), the condition elif e.args[0] == errno.ETIMEDOUT cannot be True, resulting in the throwing of the wrong exception TTransportException(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.

  • Did you create an Apache Jira ticket? (Request account here, not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

@bwangelme bwangelme marked this pull request as ready for review April 15, 2024 05:33
@bwangelme bwangelme changed the title Fix: fix thrift timeout exception error Fix mismatched timeout exceptions. Apr 15, 2024
@bwangelme bwangelme changed the title Fix mismatched timeout exceptions. THRIFT-5777: python fix mismatched timeout exceptions. Apr 15, 2024
@bwangelme bwangelme force-pushed the fix_python_net_timeout branch 2 times, most recently from 26c051f to c3a4d67 Compare April 15, 2024 06:30
@Jens-G Jens-G added the python label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants