Google 在我重新部署之前出现 ECONNRESET 错误的云函数

Google Cloud Functions with ECONNRESET errors until I redeploy

我正在使用 Google Cloud Functions 来:

  1. 注意新的 Firebase 条目
  2. 下载 Firebase 条目中引用的文件
  3. 根据该文件生成缩略图。
  4. 将缩略图上传到云存储桶。

不幸的是,我在第 4 步中反复遇到 ECONNRESET 错误,修复它的唯一方法似乎是重新部署函数。任何想法如何进一步调试这个?

编辑:

这种情况似乎发生了很多次,当我再次尝试部署该功能时,它出错了,我不得不 运行 部署两次。是不是挂了什么东西?

您可以使用 Firebase 直接向 Firebase Support team, or open a support ticket 报告错误以解决特定问题。

您还可以在 Google Issue Tracker 中报告 Cloud Functions 特定问题,这与 Stack Overflow 相似,因为它可以由 public 访问(但专门用于提交问题报告)。

2017 年 5 月 9 日更新

根据 this thread,google 云 nodejs API 开发人员对初始化时使用的默认值进行了一些更改,应该可以解决这些 ECONNRESET 套接字问题。

来自@stephen++ github GoogleCloudPlatform/google-cloud-node 问题 2254:

We have disabled the forever agent by default in Cloud Function environments. If you un- and re-install @google-cloud/storage, you will pick up the new behavior automatically. Thanks for all of the helpful debugging, everyone!


较早的 Post 关注:

对于我在云函数平台上使用存储的类似 ECONNRESET 问题的解决方案是使用 npm:promise-retry,但设置您自己的重试策略,因为默认的 10 次重试太多了。

我报告了一个 ECONNRESET issue with cloud functions to Google Support(如果您在此上下文中也获得了 ECONNRESET,但在其他上下文中没有,您可能会加注星标)并且他们以 "won't fix" 回复该行为是预期的。 Google 支持表示 API 客户端库用于连接的套接字在几分钟后超时,然后当您的云函数尝试再次使用它时,您会收到 ECONNRESET。他们建议在初始化存储 API 时添加 autoRetry:true,但这没有帮助。

ECONNRESET 也发生在读取端。在读取和写入的情况下,promise-retry 都有帮助,而且大多数情况下,只需重试 1 次即可重置坏的套接字。

所以我写了 npm:pipe-to-storage 到 return 承诺重试,检查 md5 等,但我没有用二进制数据测试它,只有文本,所以我不不知道你是否可以将它用于图像文件。调用将如下所示:

const fs = require('fs');
const storage = require('@google-cloud/storage')();
const pipeToStorage = require('pipe-to-storage')(storage);
const source = ()=>(fs.createReadStream("/path/to/your/file/to/upload"));
pipeToStorage(source, bucketName, fileNameInBucket).then(//do next step);

另见