Pull timeout with google-api-python-client

1,290 views
Skip to first unread message

y...@consumerphysics.com

unread,
Mar 21, 2016, 2:23:49 PM3/21/16
to Google Cloud Pub/Sub Discussions
Hi.

I am trying to pull with a user set timeout instead of the default 90 seconds pull:

PUBSUB_SCOPES = ['https://www.googleapis.com/auth/pubsub']

credentials = oauth2client.GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
credentials = credentials.create_scoped(PUBSUB_SCOPES)

http = httplib2.Http(timeout=timeout)
credentials.authorize(http)

return discovery.build('pubsub', 'v1', http=http)

But when I test my code with 3 seconds timeout, I get an SSL error:

    resp = client.projects().subscriptions().pull(subscription=subscription, body=body).execute()
  File "venv\lib\site-packages\oauth2client\util.py", line 137, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "venv\lib\site-packages\googleapiclient\http.py", line 755, in execute
    method=str(self.method), body=self.body, headers=self.headers)
  File "venv\lib\site-packages\googleapiclient\http.py", line 93, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "venv\lib\site-packages\oauth2client\client.py", line 622, in new_request
    redirections, connection_type)
  File "venv\lib\site-packages\httplib2\__init__.py", line 1609, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "venv\lib\site-packages\httplib2\__init__.py", line 1351, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "venv\lib\site-packages\httplib2\__init__.py", line 1307, in _conn_request
    response = conn.getresponse()
  File "C:\python27\Lib\httplib.py", line 1074, in getresponse
    response.begin()
  File "C:\python27\Lib\httplib.py", line 415, in begin
    version, status, reason = self._read_status()
  File "C:\python27\Lib\httplib.py", line 371, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "C:\python27\Lib\socket.py", line 476, in readline
    data = self._sock.recv(self._rbufsize)
  File "C:\python27\Lib\ssl.py", line 714, in recv
    return self.read(buflen)
  File "C:\python27\Lib\ssl.py", line 608, in read
    v = self._sslobj.read(len or 1024)
SSLError: ('The read operation timed out',)


Thanks, Yuval.

Alex Mordkovich

unread,
Mar 21, 2016, 6:55:05 PM3/21/16
to y...@consumerphysics.com, Google Cloud Pub/Sub Discussions
I believe this is covered by https://cloud.google.com/pubsub/troubleshooting#socket_timeout_exception.
If you don't want the pull() operation to hang waiting for more messages, you can setReturnImmediately(true) in your requests.

Confidentiality Note:

This email and the information transmitted in this email, including within any attachments, is confidential and/or privileged information. The information contained herein is intended only for the person/s or entity to which it is addressed. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient/s is prohibited.

If you received this in error, please destroy the message and any attachment and contact us immediately at in...@consumerphysics.com.

--
You received this message because you are subscribed to the Google Groups "Google Cloud Pub/Sub Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cloud-pubsub-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-pubsub-discuss/ee502eb7-3d3a-4c08-937f-8a38efba9aaa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yuval Drori

unread,
Mar 22, 2016, 3:04:24 AM3/22/16
to Alex Mordkovich, Google Cloud Pub/Sub Discussions
On the javascript side I found this:
And this:
Should I learn from this that variable long poll timeouts are on the roadmap?

Thanks.

Nicholas Gelinas

unread,
Mar 22, 2016, 12:24:05 PM3/22/16
to Google Cloud Pub/Sub Discussions
Were you able to set a longer deadline or switch to returning immediately as suggested by Alex?

As for the Javascript feature, this later issue 981 seems to suggest much approval from the current team working on PubSub so it maybe likely but not confirmed.

Yuval Drori

unread,
Mar 22, 2016, 12:58:18 PM3/22/16
to Nicholas Gelinas, Google Cloud Pub/Sub Discussions

When I set the timeout to 91 seconds I get no errors.
I can have my own timed loop in it I can pull with immediate return = True, but that is not really long polling and not very efficient.


--
You received this message because you are subscribed to a topic in the Google Groups "Google Cloud Pub/Sub Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cloud-pubsub-discuss/4AwNT2YDb7I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cloud-pubsub-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cloud-pubsub-discuss/c407a5e2-fcf1-4a75-921f-d56cb2819ac2%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Nicholas Gelinas

unread,
Mar 22, 2016, 2:25:13 PM3/22/16
to Google Cloud Pub/Sub Discussions
Thank you for posting your issue and the workaround/solution you've found publicly. It is much appreciated.

Stay tune on Issue 981 I suppose, for updates to the JS pull timeout feature request!


On Monday, March 21, 2016 at 2:23:49 PM UTC-4, y...@consumerphysics.com wrote:
Reply all
Reply to author
Forward
0 new messages