简体   繁体   English

Firebase Function Firebase 错误:deadline-exceeded 还没有超时

[英]Firebase Function Firebase Error: deadline-exceeded when it hasn't timed out yet

I have a firebase v2 function set to timeout in 540 seconds however httpsCallableFromURL catches with an error saying Firebase Error: deadline-exceeded before the function finishes.我有一个 firebase v2 function 设置为在 540 秒内超时,但是httpsCallableFromURL捕获并显示错误Firebase Error: deadline-exceeded

Here's the template of my firebase function:这是我的 firebase function 的模板:

exports.functionname = functions.https.onCall(
  {
    timeoutSeconds: 540,
    cpu: 2,
  },
  async (req) => { 
  
    const getOutput = async (id: string) => {
      return new Promise((resolve, reject) => {
        return axios.get('ur'l)
          .then((res) => {
            resolve(res.data)
          })
          .catch((e) => {
            resolve(false)
          })
      })
    }

    let output: any

    const recurse = async () => {
      return new Promise(async (resolve) => {
        // first try getting output
        output = await getOutput(id).then((res) => {
          return res
        })

        // check for output
        if (output.output) {
          return resolve(true)
        } else if (output.error) {
          return resolve(false)
        } else {
          setTimeout(() => {
            return resolve(recurse())
          }, 2000)
        }
      })
    }

    return recurse()
      .then(async () => {
        const imageUrl = output.output[0]

        function getBase64(url: string) {
          return axios
            .get(url, {
              responseType: 'arraybuffer',
            })
            .then((response) =>
              Buffer.from(response.data, 'binary').toString('base64'),
            )
        }

        const base64Image = await getBase64(imageUrl)

        const data = {
          type: 'image',
          predictionId,
          result: base64Image,
        }

        return data
        }
      })
      .catch((e) => {
        return false
      })

 },
)

If I monitor the function logs it ends up finishing within the 540 seconds but my client never receives the return value since the httpsCallableFromURL errored out.如果我监控 function 日志,它最终会在 540 秒内完成,但我的客户端从未收到返回值,因为httpsCallableFromURL出错了。

This issue involves some debugging with calculating execution time for each Promise because your Error is related to the timeout that is specified in the function which is 540 sec means all of your promises should be resolved or rejected in the given 540 secs.此问题涉及一些调试,计算每个 Promise 的执行时间,因为您的错误与 function 中指定的超时相关,即 540 秒意味着您的所有承诺都应在给定的 540 秒内解决或拒绝。

So I will recommend you to place some console.time(“Promise 1”) and console.timeEnd(“Promise 1”) around each Promises so we can get expected execution time for each promise and compare the total execution time of function and with this data you can modify the the corresponding promise which takes a lot of time.所以我会建议你在每个 Promise 周围放置一些console.time(“Promise 1”)console.timeEnd(“Promise 1”)这样我们就可以得到每个 promise 的预期执行时间并将 function 的总执行时间与这个数据你可以修改对应的 promise 这需要很多时间。 For more about this topic go through this thread有关此主题的更多信息 go 通过此线程

And In the end If above all doesn't work then you can just increase the timeout to 1800 sec means 30 mins to complete all the execution within the given timeout, but this should be avoided as a best practice.最后,如果以上都不起作用,那么您可以将超时增加到 1800 秒,这意味着 30 分钟可以在给定的超时内完成所有执行,但作为最佳实践,应该避免这种情况。

Changing the memory limit to 16GiB and cpu to 4 seems to have solved this issue:将 memory 限制更改为 16GiB 并将 cpu 更改为 4 似乎已经解决了这个问题:

exports.functionname = functions.https.onCall(
  {
    timeoutSeconds: 540,
    cpu: 4,
    memory: '16GiB',
  },
  async (req) => {

  },
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:使用 firebase 云函数时已超过期限 - Error: deadline-exceeded when working with firebase cloud functions Firebase 云函数部署错误 - 超出配额 - Firebase Cloud Functions Deploy Error - Quota Exceeded firebase 电话身份验证不发送短信,收到此错误 [SmsRetrieverHelper] 等待短信超时 - firebase phone authentication not sending sms, got this Error [SmsRetrieverHelper] Timed out waiting for SMS Firebase function 尝试写入 firebase 存储“Firebase 存储:用户无权访问”时出错 - Firebase function getting error when trying to write to firebase storage "Firebase Storage: User does not have permission to access" etcdctl 抛出错误:超出上下文截止日期错误 - etcdctl throws Error: context deadline exceeded error 处理 Python 中的 Firebase 'Max retries exceeded with url' 错误 - Handling Firebase 'Max retries exceeded with url' error in Python firebase 超出配额(每天?) - firebase quota exceeded (per day?) Firebase 删除不存在的键时数据库不返回错误 - Firebase Database doesn't return error when removing a nonexistent key Firebase 已超出此项目错误的云存储配额 - Firebase cloud storage quota has been exceeded for this project error Firebase function 从 Firebase 流式传输文件时超时 - Firebase function time-out when streaming file from Firebase Storage on emulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM