Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Detecting GCE sometimes takes forever. #93

Closed
craigcitro opened this issue Dec 16, 2014 · 20 comments
Closed

Detecting GCE sometimes takes forever. #93

craigcitro opened this issue Dec 16, 2014 · 20 comments

Comments

@craigcitro
Copy link
Contributor

on some networks (@dhermes has one at home), doing a lookup on a bogus URL takes ~20-30s. this means that the default way of discovering the current environment (say for fetching the application default credential) can be insanely slow.

@craigcitro
Copy link
Contributor Author

this was originally misdiagnosed in #92

@dhermes
Copy link
Contributor

dhermes commented Dec 16, 2014

Now running gcloud auth and other commands I realize it has always stalled for a really long time on my machines. It seems this could be the cause there as well.

@craigcitro
Copy link
Contributor Author

we definitely need to fix this, but there's no clear answer; deferring to @anthmgoogle to decide how to do this consistently for usable auth libraries.

craigcitro added a commit to craigcitro/oauth2client that referenced this issue Dec 19, 2014
This is a temporary workaround for googleapis#93, though may end up being the final fix.

I did some test cleanup while I was here, switching to `mock`.
craigcitro added a commit to craigcitro/oauth2client that referenced this issue Dec 19, 2014
This is a temporary workaround for googleapis#93, though may end up being the final fix.

I did some test cleanup while I was here, switching to `mock`.
@dhermes
Copy link
Contributor

dhermes commented Dec 20, 2014

FYI this didn't actually fix the issue, I think the slowdown is something other than timeout (DNS related).

#100 will be fine I guess?

@craigcitro
Copy link
Contributor Author

😢 #100 won't help you when you still need to fall through to 3LO, i.e. all the time.

just for kicks, can you try installing requests and doing the same thing? does it have the smarts to avoid this? (i'm guessing "no", but want to confirm.)

@craigcitro
Copy link
Contributor Author

or urllib for that matter.

@dhermes
Copy link
Contributor

dhermes commented Dec 21, 2014

In [3]: %paste
start = time.time()
try:
    requests.get('http://github.com/', timeout=0.001)
except:
    pass
print time.time() - start
## -- End pasted text --
0.0234730243683

In [4]: %paste
start = time.time()
try:
    requests.get('http://metadata.google.internal/', timeout=0.001)
except:
    pass
print time.time() - start
## -- End pasted text --
20.0183758736

I'm trying to read about ways to avoid this but not having much luck.

Seemed promising, but meh: http://askubuntu.com/questions/272358/extrememly-slow-dns-lookup

@craigcitro craigcitro reopened this Dec 21, 2014
@craigcitro
Copy link
Contributor Author

yeah, there's no way around doing some refactoring and just doing this check at the veeeery last minute. that's also what the AWS SDK does, it seems.

in the short term, here's a tweak to fix it for now ... thoughts?

@dhermes
Copy link
Contributor

dhermes commented Dec 21, 2014

It seems very hacky. You should keep trying to send this up the chain.

There should be either

  • a dependable and fast way to check if running in GCE
  • no emphasis on code which can guess which environment it's in

@erwanor
Copy link
Contributor

erwanor commented Dec 22, 2014

Just a suggestion but if it is a network dependent issue then maybe using custom DNS servers (8.8.8.8 for example) would solve the problem. The "technique" looks well documented and not too difficult to implement (http://stackoverflow.com/questions/2236498/tell-urllib2-to-use-custom-dns).

@dhermes
Copy link
Contributor

dhermes commented Dec 22, 2014

@aaronwinter Thanks for the suggest. AFAICT using a custom nameserver depends on some system internals like dig or host which may not be on every machine with a valid Python install.

Maybe the source of dnspython will reveal something.

@erwanor
Copy link
Contributor

erwanor commented Dec 23, 2014

I am not too sure if you are comfortable with using a different API but we can swap out the resolver trivially with twisted for example. Let me know if it is ok and I will implement a solution using it asap.

@craigcitro
Copy link
Contributor Author

@aaronwinter in this case, we know what IP the hostname resolves to, so i think we don't want to go the twisted/dnspython route.

i think the best solution on the table is a three-pronged attack:

  • refactor the code a bit so that we can avoid the GCE check in more cases,
  • possibly switch to using the IP with a short timeout, and
  • add an env var that says "i'm definitely not on gce, don't bother checking".

@craigcitro
Copy link
Contributor Author

The first step (switch to the IP for the metadata service) is bf9d46e.

@erwanor
Copy link
Contributor

erwanor commented Jan 8, 2015

Ok, thanks for the directions! Do you want the env var to be set to ~"no need to check" once a negative check has been done or something that is by default to "not check gce" and that the user will need to modify to enable gce checking?

@dhermes
Copy link
Contributor

dhermes commented Jan 12, 2015

@craigcitro Care to close this out?

@craigcitro
Copy link
Contributor Author

@dhermes i figured we'd leave it until all the steps above were done, but maybe we should track those separately ...

@dhermes
Copy link
Contributor

dhermes commented Jan 12, 2015

Which steps remain? You referring to #111?

I like to use check-marks to track a plan of work in progress (see googleapis/google-cloud-python#451 for example).

@erwanor
Copy link
Contributor

erwanor commented Mar 18, 2015

@dhermes I think @craigcitro is referring to this one:

refactor the code a bit so that we can avoid the GCE check in more cases,

For future reference:

  • refactor the code a bit so that we can avoid the GCE check in more cases,
  • possibly switch to using the IP with a short timeout
  • add an env var that says "i'm definitely not on gce, don't bother checking".

@theacodes
Copy link
Contributor

Thank you for creating this issue, however, this project is deprecatedand we will only be addressing critical security issues. You can read moreabout this deprecation here.

If you need support or help using this library, we recommend that you ask yourquestion on StackOverflow.

If you still think this issue is relevant and should be addressed, pleasecomment and let us know!

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

No branches or pull requests

4 participants