首页 > 解决方案 > Firebase 消息:应用程序/网络超时(发出请求时出错:超过 10000 毫秒的超时)

问题描述

我在节点 JS 服务器上使用 firebase 的管理 SDK。我注意到,一整批通知通常会在没有明显原因的情况下失败。它在大多数情况下都可以正常工作,并且突然之间,连续 20 条通知显示超时。

完整的错误信息是:

{
  code: "app/network-timeout",
  message: "Error while making request: timeout of 10000ms exceeded."
}

我使用的代码总结如下:

const admin = require('firebase-admin');
admin.initializeApp({
  credential: [...],
  databaseURL: 'https://[...].firebaseio.com'
});

const message = {
  notification: {
    title: "My title",
    body: "My content"
  },
  token: token
}

admin.messaging().send(message)
    .then((response) => {
      // message sent with success (most of the time)
    })
    .catch((err) => {
      // message error: timeout
    })

我认为这可能与定价计划有关,因为我通常在使用有限的 firebase 功能时遇到这种故障,但消息在定价计划中显示为“免费”。无论如何,我都切换到火花,以防万一,我会监控任何变化。

我找不到任何人报告此类问题,知道为什么我使用Firebase Messaging随机超时?

标签: node.jsfirebasefirebase-cloud-messagingfirebase-admin

解决方案


错误消息提示我您的服务器暂时无法访问 FCM 服务器。就是说超过了10秒的超时时间。如果您收到此错误消息,您应该重试 API 以发送消息。

网络问题确实时有发生,并且您的服务器和 Firebase 之间可能有十几个您无法控制的网络跃点。网络故障重试对于容错始终很重要。


推荐阅读