algorithmia-python icon indicating copy to clipboard operation
algorithmia-python copied to clipboard

Requests hang Indefinitely when waiting for network/missing timeout value

Open rwnx opened this issue 3 years ago • 0 comments

Hi,

I've been troubleshooting a bug where this client will hang forever waiting for a response in some cases.

I noticed that calls using the requests library are not using the timeout= option which is recommended: https://2.python-requests.org/en/master/user/quickstart/#timeouts

You can tell Requests to stop waiting for a response after a given number of seconds with the timeout parameter. Nearly all production code should use this parameter in nearly all requests. Failure to do so can cause your program to hang indefinitely

I've put together a PR #40 for changing this to 5 seconds (if this seems low, the notes from requests make this a little clearer: it's the time between bytes rather than the entire request) to establish a sensible default for the library to be making calls under.

More info from the docs:

timeout is not a time limit on the entire response download; rather, an exception is raised if the server has not issued a response for timeout seconds (more precisely, if no bytes have been received on the underlying socket for timeout seconds). If no timeout is specified explicitly, requests do not time out.

rwnx avatar Sep 25 '20 15:09 rwnx