socket.timeout with will cause api client to become unuseable
See original GitHub issueWe recently ran into a socket.timeout issue using the google api client, and noticed that then all our requests would fail in the same way. I later find that connections are cached here: https://github.com/httplib2/httplib2/blob/master/python3/httplib2/__init__.py#L1759
however there is no code to remove cached connections that are bad. This is a major oversight.
Here’s the callstack we hit:
batch_entry.batch.execute(http=http, num_retries=num_retries)
File "/pyenv/lib/python3.6/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/pyenv/lib/python3.6/site-packages/googleapiclient/http.py", line 1465, in execute
self._execute(http, self._order, self._requests, num_retries)
File "/pyenv/lib/python3.6/site-packages/googleapiclient/http.py", line 1394, in _execute
body=body, headers=headers)
File "/pyenv/lib/python3.6/site-packages/googleapiclient/http.py", line 185, in _retry_request
raise exception
File "/pyenv/lib/python3.6/site-packages/googleapiclient/http.py", line 165, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "/pyenv/lib/python3.6/site-packages/oauth2client/transport.py", line 175, in new_request
redirections, connection_type)
File "/pyenv/lib/python3.6/site-packages/oauth2client/transport.py", line 282, in request
connection_type=connection_type)
File "/pyenv/lib/python3.6/site-packages/httplib2/__init__.py", line 1514, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/pyenv/lib/python3.6/site-packages/httplib2/__init__.py", line 1264, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/pyenv/lib/python3.6/site-packages/httplib2/__init__.py", line 1217, in _conn_request
response = conn.getresponse()
File "/usr/local/lib/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/usr/local/lib/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/local/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "/usr/local/lib/python3.6/ssl.py", line 1009, in recv_into
return self.read(nbytes, buffer)
File "/usr/local/lib/python3.6/ssl.py", line 871, in read
return self._sslobj.read(len, buffer)
File "/usr/local/lib/python3.6/ssl.py", line 631, in read
v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Taking a Timeout from Poor Performance
This article explains how you can make your applications remain performant when upstream dependencies are not, using timeouts and retries.
Read more >Artificially create a connection timeout error
Hi Mark, I tried solution that work for you but what I'm receiving is #503 (Service Unavailable.). Isn't should be one of these,...
Read more >Better performance: the case for timeouts - Alessandro Nadalin
Use timeouts to build more robust and less expensive distributed systems: less memory, less downtime, more fun!
Read more >408 Request Timeout - HTTP - MDN Web Docs
It is sent on an idle connection by some servers, even without any previous request by the client.
Read more >504 Gateway Timeout | Apigee Edge
What causes gateway timeouts? Typical path for an API request via the Edge platform will be Client -> Router -> Message Processor ->...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
actually no, it’s post 0.12.0 (806de52a2939d95800e43b1ab96be45a33b882d1 vs 806de52a2939d95800e43b1ab96be45a33b882d1 for 0.12.0), supposedly 12.1. This should be re-opened
After hours of hacking api code, found the solution.
Make note the order -
socket.setdefaulttimeout(timeoutInSec)
needs to be before any import ofgoogleapiclient
. No magic happens instead 😉