firebase - Firebase 云函数 - 未处理的错误 RangeError
问题描述
这是我部署的唯一功能:
exports.gameAction = functions.https.onCall((data, context) => {
const timeoutRef = admin.database().ref('/current_player/timeout');
return timeoutRef.transaction((timeout) => {
return;
});
});
如果我理解正确,事务将在调用后立即中止,但是当我从我的应用程序调用此函数时,控制台会显示以下错误:
Unhandled error RangeError: Maximum call stack size exceeded
at Object (native)
at baseGetTag (/user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:3087:51)
at Function.isBoolean (/user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:11383:33)
at encode (/user_code/node_modules/firebase-functions/lib/providers/https.js:229:11)
at /user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:13400:38
at /user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:4925:15
at baseForOwn (/user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:3010:24)
at Function.mapValues (/user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:13399:7)
at encode (/user_code/node_modules/firebase-functions/lib/providers/https.js:242:18)
at /user_code/node_modules/firebase-functions/node_modules/lodash/lodash.js:13400:38
我在这里想念什么?
解决方案
onCall 函数将数据发送回客户端的方式是返回一个承诺,该承诺与要发送的对象数据一起解析。因此,Cloud Functions 尝试将事务返回的 Promise 中包含的数据序列化,然后以 JSON 格式发送给客户端。
正如您从transaction()的 API 文档中看到的那样,promise 包含一个 Reference 对象,其中包含有关该引用的各种元数据。它可能包含一个循环数据结构,而 Cloud Functions 一直在尝试序列化无限循环。
试着从你的函数中返回一些不太复杂的东西。
推荐阅读
- python - 写入 GML 文件时出现 NetworkX 密钥错误
- android - Android单元测试中的资源文件访问“InvocationTargetException”
- python - 考虑顺序对 pandas 列执行累积计数
- html - Firefox 忽略最小宽度和最大宽度的图像尺寸属性
- c++ - 基本形状识别(openCV C++)
- c# - ASP.NET Core:调用之间的空闲超时有延迟
- c++ - 在模板元编程中使用列表类型
- c# - 从另一个线程调用时不会触发操作
- c# - 在 asp.net 网络表单中注册后,如何通过电子邮件从 sql 数据库向用户发送自动生成的 ID
- r - 在 ddply/dlply 中嵌套 nlm 函数