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

Unexpected error determining execution environment: request to http://metadata.google.internal./computeMetadata/v1/instance failed, reason: socket hang up #711

Closed
mrdulin opened this issue May 18, 2019 · 9 comments
Assignees
Labels
needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue. web

Comments

@mrdulin
Copy link

mrdulin commented May 18, 2019

Environment details

  • OS: macOS Mojave 10.14.4 (18E226)
  • Node.js version: v8.10.0
  • npm version: 6.9.0
  • google-auth-library version: "^4.0.0"
  • "ts-node": "^7.0.1",

Steps to reproduce

  1. Here is the official example:
import { auth } from 'google-auth-library';

async function main() {
  const client = await auth.getClient({
    scopes: 'https://www.googleapis.com/auth/cloud-platform',
    clientOptions: {}
  });
  const projectId = await auth.getProjectId();
  const url = `https://www.googleapis.com/dns/v1/projects/${projectId}`;
  const res = await client.request({ url });
  console.log(res.data);
}

main().catch((error) => {
  console.error(JSON.stringify(error, null, 2));
});
  1. set https_proxy
echo $https_proxy
http://127.0.0.1:1087
  1. verify the proxy server is working

image

  1. run the example code, get this error:
{
  "message": "Unexpected error determining execution environment: request to http://metadata.google.internal./computeMetadata/v1/instance failed, reason: socket hang up",
  "type": "system",
  "errno": "ECONNRESET",
  "code": "ECONNRESET",
  "config": {
    "url": "http://metadata.google.internal./computeMetadata/v1/instance",
    "headers": {
      "Metadata-Flavor": "Google"
    },
    "retryConfig": {
      "noResponseRetries": 0,
      "currentRetryAttempt": 0,
      "retry": 3,
      "retryDelay": 100,
      "httpMethodsToRetry": [
        "GET",
        "HEAD",
        "PUT",
        "OPTIONS",
        "DELETE"
      ],
      "statusCodesToRetry": [
        [
          100,
          199
        ],
        [
          429,
          429
        ],
        [
          500,
          599
        ]
      ]
    },
    "responseType": "text",
    "params": {},
    "method": "GET",
    "agent": {
      "domain": null,
      "_events": {},
      "_eventsCount": 0,
      "_promisifiedCallback": true,
      "timeout": null,
      "options": {
        "protocol": "http:",
        "slashes": true,
        "auth": null,
        "host": "127.0.0.1:1087",
        "port": "1087",
        "hostname": "127.0.0.1",
        "hash": null,
        "search": null,
        "query": null,
        "pathname": "/",
        "path": "/",
        "href": "http://127.0.0.1:1087/"
      },
      "secureProxy": false,
      "proxy": {
        "protocol": "http:",
        "slashes": true,
        "auth": null,
        "host": "127.0.0.1",
        "port": 1087,
        "hostname": "127.0.0.1",
        "hash": null,
        "search": null,
        "query": null,
        "href": "http://127.0.0.1:1087/"
      },
      "defaultPort": 443
    }
  }
}
@JustinBeckwith
Copy link
Contributor

Greetings! It looks like the code you're running is trying to get credentials from the GCE Metadata server, which should only really happen if you're running inside of Google Cloud.

Are you running this code locally? In a VM? Knowing where it's running would be super helpful :)

@JustinBeckwith JustinBeckwith added needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue. triage me I really want to be triaged. labels May 20, 2019
@mrdulin
Copy link
Author

mrdulin commented May 21, 2019

@JustinBeckwith Thanks for reply. I am running this code locally. Yes, I know GCE Metadata, for some reason, the network in my country can't connect to google domain, that's why I am trying to use a proxy server.

BTW, the proxy server works fine. I am sure about that.

@marcospgp
Copy link

I just got this issue as well. Found this open issue but will keep looking as I hope I don't have to wait for a fix to get through this :)

Trying to use the bigquery API from inside a docker container, locally. Node.js application.

@marcospgp
Copy link

Aaand I forgot to load our .env file!

Unfortunately I am a little used to Google libraries returning these nonspecific errors and having to fish around for the problem 😢

Hope we keep improving though! Great work guys, thanks 😄

@bcoe
Copy link
Contributor

bcoe commented Oct 18, 2019

@mrdulin are you continuing to bump into issues connecting through a proxy?

@mattfarkas
Copy link

also running into this error when trying to hit BQ from React. Tried running with/without specifying a service account cred file and neither seems to work.

also getting this error from time to time and not sure how to interpret:

googleauth.js:587 Uncaught (in promise) TypeError: fs.createReadStream is not a function

@bcoe
Copy link
Contributor

bcoe commented Oct 28, 2019

@mattfarkas I believe this is likely a different issue, related to the fact that fs.createReadStream is not available by default when webpacking.

It might be worth referencing a blog post like this:

https://blog.angularindepth.com/google-apis-with-angular-214fadb8fbc5

Which another user wrote up regarding porting googleapis to a Webpacked environment.

@trojans10
Copy link

@mattfarkas did you figure anything out? samething with react + bq

@bcoe
Copy link
Contributor

bcoe commented Nov 4, 2019

@mrdulin I'm closing this thread for now, there have been a few bug fixes to our metadata library, and I'm hoping you're back on your feet -- please feel free to reopen if you're continuing to bump in to issues.

@mattfarkas @trojans10, there's a blog post here you might check out, about about bundling our libraries with WebPack:

https://blog.angularindepth.com/google-apis-with-angular-214fadb8fbc5

there is also some documentation here, on how to run our gRPC libraries with an HTTP fallback (which makes it possible to run them in React front-end):

googleapis/google-cloud-node#2933

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue. web
Projects
None yet
Development

No branches or pull requests

7 participants