【问题标题】:Firebase Cloud Functions Shell not executing write operations on realtime databaseFirebase Cloud Functions Shell 未在实时数据库上执行写操作
【发布时间】:2017-12-24 16:12:12
【问题描述】:

由于几天以来我无法再在本地测试云功能,因为所有写入功能都没有执行并且没有任何返回,因此该功能挂起并最终因超时而停止。

示例函数:

import { database as dbEvent } from "firebase-functions";

export default dbEvent.ref("/tariffs/removeHistory").onCreate((event: any) => {
  console.log("START");
  const bikesHistoryRef = event.data.adminRef.parent.parent.child("bikesHistory");
  return bikesHistoryRef.set(null).then((res) => console.log("Delete done", res));
});

结果:

firebase > removeBikeHistory("test")
'Successfully invoked function.'
firebase > info: User function triggered, starting execution
info: START

firebase > 
firebase > info: Execution took 61023 ms, finished with status: 'timeout'
info: Execution took 49694 ms, finished with status: 'crash'

有什么建议吗?我的所有云功能都会出现这种情况,当我部署它们时,它就可以工作。

我试过了:

firebase-admin@5.5.1
firebase-functions@0.7.3
firebase-tools@3.15.4 (-g)

firebase-admin@5.6.0
firebase-functions@0.7.5
firebase-tools@3.16.0 (-g)

编辑:

启用日志记录后,我收到以下错误:

info: 0: onDisconnectEvents 
info: p:0: Making a connection attempt 
info: p:0: Failed to get token: Error: Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2 access token with the following error: "Error fetching access token: invalid_grant (Bad Request)". There are two likely causes: (1) your server time is not properly synced or (2) your certificate key file has been revoked. To solve (1), re-sync the time on your server. To solve (2), make sure the key ID for your key file is still present at https://console.firebase.google.com/iam-admin/serviceaccounts/project. If not, generate a new key file at https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk. 
p:0: data client disconnected 
info: p:0: Trying to reconnect in 1283.8299240003184ms 
0: onDisconnectEvents 

我在安装较旧的 firebase-function/admin 版本时确实看到了此错误,但我认为通过安装较新版本可以解决此问题。我该如何解决?

【问题讨论】:

  • 如果在对数据库进行任何操作之前启用日志记录会发生什么? admin.database.enableLogging(true)firebase.google.com/docs/reference/admin/node/…
  • 另外,你使用gcloud命令行吗?
  • 我不使用 gcloud CLI,只使用 firebase CLI。我应该使用 gcloud 吗?我现在启用了日志记录,请参阅上面我的帖子中的编辑。
  • 感谢 Doug,感谢您的日志提示,我找到了解决方案,见下文。

标签: firebase google-cloud-functions


【解决方案1】:

我在这个错误报告中找到了解决方案: https://github.com/firebase/firebase-functions/issues/135

我已删除以下文件,现在我的云功能再次在本地工作:

rm ~/.config/gcloud/application_default_credentials.json 

【讨论】:

  • 如果你有 gcloud,你也可以运行gcloud auth application-default login 来重置它。
猜你喜欢
  • 2019-10-03
  • 2019-09-25
  • 2017-10-26
  • 1970-01-01
  • 2020-09-01
  • 1970-01-01
  • 2017-11-12
  • 2021-11-17
  • 2017-09-03
相关资源
最近更新 更多