这是indexloc提供的服务,不要输入任何密码
Skip to content

Unhandled network error rejection when using storage API #5372

@VeryCrazyDog

Description

@VeryCrazyDog

Describe your environment

  • Operating System version: Windows 10
  • Browser version: N/A (Node.js 14)
  • Firebase SDK version: 8.10.0
  • Firebase Product: storage

Describe the problem

Steps to reproduce:

  1. Simulate network error such as disconnect from network, blocking DNS server, blocking outgoing traffic, etc.
  2. Execute storage API such as getMetadata() or getDownloadURL().
  3. Unhandled promise rejection is thrown. A sample console log is at below. My expected result is throwing FirebaseError with code storage/retry-limit-exceeded.
C:\Users\VCD\Developer\playground>node --unhandled-rejections=throw fbstorage-bug.js

C:\Users\VCD\Developer\playground\node_modules\node-fetch\lib\index.js:1461
                        reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
                               ^
FetchError: request to https://firebasestorage.googleapis.com/v0/b/xxxxxxxxxxxxxxxxx.appspot.com/o/image.png failed, reason: getaddrinfo ENOTFOUND firebasestorage.googleapis.com
    at ClientRequest.<anonymous> (C:\Users\VCD\Developer\playground\node_modules\node-fetch\lib\index.js:1461:11)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  type: 'system',
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND'
}

Relevant code:

'use strict'

const firebase = require('firebase/app')
require('firebase/storage')

const app = firebase.initializeApp({
  apiKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  authDomain: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  projectId: 'xxxxxxxxxxxxxxxxx',
  storageBucket: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  messagingSenderId: 'xxxxxxxxxxxx',
  appId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
})
const storage = app.storage()

// Remember to disconnect the network before running
;(async () => {
  const ref = storage.ref('/image.png')
  const rtv = await ref.getMetadata()
  console.log(rtv)
  console.log('END')
})().catch(error => {
  console.log('EXCEPTION')
  if (error.stack) {
    console.error(error.stack)
  } else {
    console.error(error)
  }
}).finally(async () => {
  await app.delete()
})

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions