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, timeout retrieving metadata with older 3.2.1 version #1368

Closed
bdefore opened this issue Dec 20, 2020 · 1 comment
Assignees
Labels
api: storage Issues related to the googleapis/nodejs-storage API. external This issue is blocked on a bug with the actual product. 🚨 This issue needs some love. triage me I really want to be triaged.

Comments

@bdefore
Copy link

bdefore commented Dec 20, 2020

Environment details

  • OS: Ubuntu Xenial or Ubuntu Trusty on a Netlify build (did not present on Manjaro which had GOOGLE_APPLICATION_CREDENTIALS exported)
  • Node.js version: 12.16.1
  • npm version: yarn 1.3.2
  • @google-cloud/storage version: 3.2.1 (fixed by upgrading to latest 5.7.0)
  • firebase version: 7.5.0 (in attempting to diagnose, updated to 8.2.1)

Steps to reproduce

I use firebase npm library to authenticate with email and password. This is my sign in logic:

const firebase = require('firebase/app')
require('firebase/auth')
require('firebase/database')

let _app

const app = () => {
  if (!_app) {
    console.log(`Initializing Firebase Realtime Database project: REDACTED`)
    _app = firebase.initializeApp(config)
  }
  return _app
}

export const signInWithGoogleCredentials = () => {
  // Sign in with credential from the Google user.
  return app().auth().signInWithEmailAndPassword(process.env.FIREBASE_STORAGE_USER_EMAIL, process.env.FIREBASE_STORAGE_USER_PASSWORD)
    .then(result => {
      const { email, uid } = app().auth().currentUser
      console.log(`Logged in as ${email} with uid ${uid}`)
      return result
    })
}

Then I setup usage of a public bucket using this library:

const { Storage } = require('@google-cloud/storage')
const { config } = require('./config')

console.log(`Initializing Cloud Storage for project ${config.projectId}`)

const storage = new Storage({ projectId: config.projectId })
const bucket = storage.bucket(config.storageBucket)

Then I when I attempt to download a specific file by name, i attempt to get a list of all files in the bucket and use the metadata.name to find it:

const log = obj => {
  console.log('=>', JSON.stringify(obj, null, 2)) // too noisy
  return obj
}

export const getAllFiles = (path = '') => {
  return bucket.getFiles(path)
    .then(data => data[0])
    .then(files => {
      if (!files || !files.find || files.length === 0) {
        throw new Error('No files returned from bucket.getFiles! Have you made the bucket public?')
      }
      return files
    })
}

export const findInFiles = filename => getAllFiles()
  .then(log)
  .then(files => {
    // console.log('files', files.map(f => f.metadata.name))
    return files.find(f => f.metadata.name.includes(filename)) // <-- new script error occurs here
  })
  .then(log)
  .then(file => {
    if (!file) {
      throw new Error(`Could not find file ${filename}. Do you have permissions? Did you make the bucket public?`)
    }
    return file
  })
  .then(file => {
    // console.log('Found file', file.metadata)
    return file
  })
  .catch(err => {
    console.log(err)
    return err
  })

This logic has worked unchanged for at least one year but started failing yesterday, giving the following error from the log method:

7:18:01 AM: => {
7:18:01 AM:   "message": "Unexpected error determining execution environment: request to http://metadata.google.internal./computeMetadata/v1/instance failed, reason: connect ETIMEDOUT 169.254.169.254:80",
7:18:01 AM:   "type": "system",
7:18:01 AM:   "errno": "ETIMEDOUT",
7:18:01 AM:   "code": "ETIMEDOUT",
7:18:01 AM:   "config": {
7:18:01 AM:     "url": "http://metadata.google.internal./computeMetadata/v1/instance",
7:18:01 AM:     "headers": {
7:18:01 AM:       "Metadata-Flavor": "Google"
7:18:01 AM:     },
7:18:01 AM:     "retryConfig": {
7:18:01 AM:       "noResponseRetries": 0,
7:18:01 AM:       "currentRetryAttempt": 0,
7:18:01 AM:       "retry": 3,
7:18:01 AM:       "retryDelay": 100,
7:18:01 AM:       "httpMethodsToRetry": [
7:18:01 AM:         "GET",
7:18:01 AM:         "HEAD",
7:18:01 AM:         "PUT",
7:18:01 AM:         "OPTIONS",
7:18:01 AM:         "DELETE"
7:18:01 AM:       ],
7:18:01 AM:       "statusCodesToRetry": [
7:18:01 AM:         [
7:18:01 AM:           100,
7:18:01 AM:           199
7:18:01 AM:         ],
7:18:01 AM:         [
7:18:01 AM:           429,
7:18:01 AM:           429
7:18:01 AM:         ],
7:18:01 AM:         [
7:18:01 AM:           500,
7:18:01 AM:           599
7:18:01 AM:         ]
7:18:01 AM:       ]
7:18:01 AM:     },
7:18:01 AM:     "responseType": "text",
7:18:01 AM:     "params": {},
7:18:01 AM:     "method": "GET"
7:18:01 AM:   }
7:18:01 AM: }
7:18:01 AM: TypeError: files.find is not a function
7:18:01 AM:     at /opt/build/repo/src/google_cloud.js:90:18
7:18:01 AM:     at processTicksAndRejections (internal/process/task_queues.js:97:5)
7:18:01 AM:     at downloadStoredData (/opt/build/repo/src/google_cloud.js:138:3)
7:18:01 AM:     at sync (/opt/build/repo/src/sync.js:68:5)
7:18:01 AM: error TypeError: file.download is not a function
7:18:01 AM:     at /opt/build/repo/src/google_cloud.js:112:19
7:18:01 AM:     at processTicksAndRejections (internal/process/task_queues.js:97:5)
7:18:01 AM:     at downloadStoredData (/opt/build/repo/src/google_cloud.js:138:3)
7:18:01 AM:     at sync (/opt/build/repo/src/sync.js:68:5)
7:18:01 AM:     at /opt/build/repo/src/google_cloud.js:112:19
7:18:01 AM:     at processTicksAndRejections (internal/process/task_queues.js:97:5)
7:18:01 AM:     at downloadStoredData (/opt/build/repo/src/google_cloud.js:138:3)
7:18:01 AM:     at sync (/opt/build/repo/src/sync.js:68:5)
7:18:01 AM: error Command failed with exit code 1.

My resolution for this:

  • Upgrading firebase from 7.5.0 to latest 8.2.1 (unsure if this is necessary, did not resolve the issue on its own)
  • Upgrading @google-cloud/storage from 3.2.1 to latest 5.7.0

Even though this resolves the issue for me, I expect this will cause issues for anyone pinned to these older versions which as far as I can tell are still supported. The behavior of files not being an array as well as an unhelpful error message makes it difficult to diagnose the problem.

Further context:

I was unable to reproduce this issue on a Manjaro device which had GOOGLE_APPLICATION_CREDENTIALS exported. Perhaps OS is related.

I see from release notes of 8.2.1 that some authentication changes were made that may be related: https://firebase.google.com/support/release-notes/js#version_821_-_december_17_2020

Referred PRs:
firebase/firebase-js-sdk#4175
firebase/firebase-js-sdk#3222

I noticed this morning that my local ChromeOS device incorrectly detected Central time zone from my IP when I am on Eastern.

Apologies if this is actually an issue with firebase library. I can file an issue there if preferred. I can also attempt to reproduce the issue with other combinations such as the latest 3.x of this library if it would be helpful.

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Dec 20, 2020
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Dec 21, 2020
@shaffeeullah
Copy link
Contributor

Hi @bdefore, thanks for raising this issue. This seems to be an issue with the firebase library. Can you please re-open this issue here?

@frankyn frankyn removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Jan 11, 2021
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Jan 11, 2021
@shaffeeullah shaffeeullah added the external This issue is blocked on a bug with the actual product. label Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. external This issue is blocked on a bug with the actual product. 🚨 This issue needs some love. triage me I really want to be triaged.
Projects
None yet
Development

No branches or pull requests

4 participants