【发布时间】:2019-09-11 23:36:42
【问题描述】:
我在节点 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 的有限功能时遇到这种故障,但消息在定价计划中显示为“免费”。无论如何我都切换到 spark 以防万一,我会监控任何变化。
我找不到任何人报告此类问题,知道为什么我随机使用 Firebase 消息传递超时?
【问题讨论】:
-
您是否要同时发送大量消息?它可能会对 Node.js 进程造成负担,导致某些操作排队并超时。此外,如果您使用的是 v8.2.0 或更高版本,SDK 还会在抛出错误之前重试 ETIMEDOUT 错误大约 4 次。确保您使用的是最新版本。
标签: node.js firebase firebase-cloud-messaging firebase-admin