google-api-python-client: Broken Pipe exceptions raised after idle periods

I’m using long-lived client objects like so:

client = discovery.build(....)
task = client.get_something(....).execute(num_retries=5)
some_long_running_process(task)
client.do_another_thing().execute(num_retries=5)

And running into exceptions on the calls to do_another_thing():

Traceback (most recent call last):
  File "/opt/app/gcp_helper.py", line 168, in get_size
    instanceGroupManager=instance_group).execute(num_retries=5)
  File "/opt/venv/local/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/opt/venv/local/lib/python2.7/site-packages/googleapiclient/http.py", line 755, in execute
    method=str(self.method), body=self.body, headers=self.headers)
  File "/opt/venv/local/lib/python2.7/site-packages/googleapiclient/http.py", line 93, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/opt/venv/local/lib/python2.7/site-packages/oauth2client/client.py", line 633, in new_request
    self._refresh(request_orig)
  File "/opt/venv/local/lib/python2.7/site-packages/oauth2client/contrib/gce.py", line 129, in _refresh
    META, headers={'Metadata-Flavor': 'Google'})
  File "/opt/venv/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1609, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/opt/venv/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1351, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/opt/venv/local/lib/python2.7/site-packages/httplib2/__init__.py", line 1273, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1001, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python2.7/httplib.py", line 1035, in _send_request
    self.endheaders(body)
  File "/usr/lib/python2.7/httplib.py", line 997, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 850, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 826, in send
    self.sock.sendall(data)
  File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 32] Broken pipe"

I would expect the num_retries argument to handle these exceptions in https://github.com/google/google-api-python-client/blob/master/googleapiclient/http.py#L145, but for the time being I have to implement my own retry logic around all API calls to overcome this.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 49 (17 by maintainers)

Commits related to this issue

Most upvoted comments

I’m experiencing this issue as well…

Using:

Python 3.6.7

>>> import googleapiclient
>>> googleapiclient.__version__
'1.7.8'

Stack trace:

File "/var/task/pubsub_publisher.py", line 42, in handler
  pubsub.projects().topics().publish(topic=_GOOGLE_PUBSUB_TOPIC_NAME, body=body).execute() 
File "/var/task/googleapiclient/_helpers.py", line 130, in positional_wrapper
  return wrapped(*args, **kwargs)
File "/var/task/googleapiclient/http.py", line 846, in execute
  method=str(self.method), body=self.body, headers=self.headers)
File "/var/task/googleapiclient/http.py", line 183,in _retry_request
  raise exception
File "/var/task/googleapiclient/http.py", line 164, in _retry_request
  resp, content = http.request(uri, method, *args, **kwargs)
File "/var/task/google_auth_httplib2.py", line 198, in request
  uri, method, body=body, headers=request_headers, **kwargs)
File "/var/task/httplib2/__init__.py", line 1924, in request
  cachekey,
File "/var/task/httplib2/__init__.py", line 1595, in _request
  conn, request_uri, method, body, headers
File "/var/task/httplib2/__init__.py", line 1502, in _conn_request
  conn.request(method, request_uri, body, headers)
File "/var/lang/lib/python3.6/http/client.py", line 1239, in request
  self._send_request(method, url, body, headers, encode_chunked)
File "/var/lang/lib/python3.6/http/client.py", line 1285, in _send_request
  self.endheaders(body, encode_chunked=encode_chunked)
File "/var/lang/lib/python3.6/http/client.py", line 1234, in endheaders
  self._send_output(message_body, encode_chunked=encode_chunked)
File "/var/lang/lib/python3.6/http/client.py", line 1065, in _send_output
  self.send(chunk)
File "/var/lang/lib/python3.6/http/client.py", line 986, in send
  self.sock.sendall(data)
File "/var/lang/lib/python3.6/ssl.py", line 975, in sendall
  v = self.send(byte_view[count:])
File "/var/lang/lib/python3.6/ssl.py", line 944, in send
  return self._sslobj.write(data)
File "/var/lang/lib/python3.6/ssl.py", line 642, in write
  return self._sslobj.write(data)
BrokenPipeError: [Errno 32] Broken pipe

It’s something that happens now and then, not super common. Constantly recurring though.

As an example in a sample of 7,741,334 publishes I have 6 of those errors.

@Bobspadger probably not, but we’re soon replacing oauth2client in this library with google-auth, which will allow us to use urllib3 and requests without needing httplib2shim.

This is now happening to me via a Cloud Run execution that happens every 30 minutes. What’s the status of this fix?

Why was the issue closed when there is no solution or fix in place?

We have the same issue when periodically call status of long ai platform training job from CE instance. Pipe is broken after 1 hour (+/- minute) of using discovery for ml.v1 google-api-python-client==1.9.1

p.s. update to google.auth (1.24.0) did not help. The workaround is to recreate api client and retry on broken pipe exception

We are also experiencing this issue after upgrading to the latest version.

Would it be appropriate to re-open this ticket, or should I introduce a new one?

I get this with the Google drive API as well 😕

The same for me with ml engine train

Hi,

I’m having the same issue via Cloud Run also. I randomly get “Broken Pipe” or “connection reset by peer” errors. I am using the latest version of the Google API client so it seems this has not been fixed yet.

@nharpalani it’s looking unlikely that we’ll be able to replace httplib2 in this library without massive breaking changes. We’re working on a similar effort over on the google-cloud-python package and there’s a small chance that work might be transferrable here, but no promises.

Closing for now.

Sure

[2016/10/23 18:31:15] (I:googleapiclient.discovery) URL being requested: GET https://www.googleapis.com/youtube/v3/videos?id=5_LxyhCJp
sM&part=snippet%2CcontentDetails%2Cstatistics&alt=json&key=<snip>
[2016/10/23 18:31:15] (E:asyncio) Unhandled exception in event task
future: <Task finished coro=<LinkInfo.scan_privmsg() done, defined at /home/urybot/.pyenv/versions/3.5.1/lib/python3.5/asyncio/corouti
nes.py:204> exception=BrokenPipeError(32, 'Broken pipe')>
Traceback (most recent call last):
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/asyncio/coroutines.py", line 206, in coro
    res = func(*args, **kw)
  File "/home/urybot/csbot/csbot/plugins/linkinfo.py", line 155, in scan_privmsg
    result = self.get_link_info(part)
  File "/home/urybot/csbot/csbot/plugins/linkinfo.py", line 189, in get_link_info
    result = h.handler(url, match)
  File "/home/urybot/csbot/csbot/plugins/youtube.py", line 153, in page_handler
    response = self._yt(url)
  File "/home/urybot/csbot/csbot/plugins/youtube.py", line 86, in _yt
    json = self.get_video_json(vid_id)
  File "/home/urybot/csbot/csbot/plugins/youtube.py", line 73, in get_video_json
    response = self.client.videos().list(id=id, part='snippet,contentDetails,statistics').execute(http=self.http)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/site-packages/oauth2client/util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/site-packages/googleapiclient/http.py", line 833, in execute
    method=str(self.method), body=self.body, headers=self.headers)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/site-packages/googleapiclient/http.py", line 173, in _retry_request
    raise exception
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/site-packages/googleapiclient/http.py", line 160, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/site-packages/httplib2/__init__.py", line 1314, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/site-packages/httplib2/__init__.py", line 1064, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/site-packages/httplib2/__init__.py", line 988, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/http/client.py", line 1083, in request
    self._send_request(method, url, body, headers)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/http/client.py", line 1079, in endheaders
    self._send_output(message_body)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/http/client.py", line 911, in _send_output
    self.send(msg)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/http/client.py", line 885, in send
    self.sock.sendall(data)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/ssl.py", line 886, in sendall
    v = self.send(data[count:])
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/ssl.py", line 856, in send
    return self._sslobj.write(data)
  File "/home/urybot/.pyenv/versions/3.5.1/lib/python3.5/ssl.py", line 581, in write
    return self._sslobj.write(data)
BrokenPipeError: [Errno 32] Broken pipe