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

gcloud on appegnine - deadline doesn't work the way it should #24

Open
rotemvil1 opened this issue Aug 31, 2016 · 1 comment
Open

gcloud on appegnine - deadline doesn't work the way it should #24

rotemvil1 opened this issue Aug 31, 2016 · 1 comment

Comments

@rotemvil1
Copy link

rotemvil1 commented Aug 31, 2016

Hey,

During my usage in gcloud(which uses httplib2) over appengine environment I got an exceptions when my request to a url took more than 5 seconds. According to google app engine documentation when you need more than 5 seconds for a request you should use:
urlfetch.set_default_fetch_deadline(seconds)
So I did. But the problem exception kept happening. When using fetch, you are passing the deadline parameter by (line 1002):
socket.getdefaulttimeout() or 5
but it should be in this way to support appengine users:
deadline = get_default_fetch_deadline() or socket.getdefaulttimeout() or 5

Attaching my code (I'm not familiar with google3 package) :

`try:
try:
from google.appengine.api import apiproxy_stub_map
if apiproxy_stub_map.apiproxy.GetStub('urlfetch') is None:
raise ImportError # Bail out; we're not actually running on App Engine.
from google.appengine.api.urlfetch import fetch
from google.appengine.api.urlfetch import InvalidURLError
from google.appengine.api.urlfetch import get_default_fetch_deadline
except (ImportError, AttributeError):
from google3.apphosting.api import apiproxy_stub_map
if apiproxy_stub_map.apiproxy.GetStub('urlfetch') is None:
raise ImportError # Bail out; we're not actually running on App Engine.
from google3.apphosting.api.urlfetch import fetch
from google3.apphosting.api.urlfetch import InvalidURLError

def _new_fixed_fetch(validate_certificate):
    def fixed_fetch(url, payload=None, method="GET", headers={},
                    allow_truncated=False, follow_redirects=True,
                    deadline=None):
        if deadline is None:
            deadline = get_default_fetch_deadline() or socket.getdefaulttimeout() or 5
        return fetch(url, payload=payload, method=method, headers=headers,
                     allow_truncated=allow_truncated,
                     follow_redirects=follow_redirects, deadline=deadline,
                     validate_certificate=validate_certificate)
    return fixed_fetch`
@devjoe
Copy link

devjoe commented Oct 13, 2016

Hey @rotemvil1, I meet the same problem when my colleague upgrades httplib2 from an old version to 0.9.2.

However, it's no need to apply your patch here. The problem you faced was fixed in #10.

Here are two requests for maintainers:

  • Please release a patched version to avoid GAE users meet the same problem in the future.
  • Write a test to make sure that behavior of set_default_fetch_deadline will not break easily.

For the latter, I already created a PR here: #28. Wait for @jcgregorio your review. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants