gpt4 book ai didi

firebase - Google Cloud Functions 出现 ECONNRESET 错误,直到我重新部署

转载 作者:行者123 更新时间:2023-12-03 01:26:25 25 4
gpt4 key购买 nike

我使用 Google Cloud Functions 来:

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

不幸的是,我在第 4 步中反复遇到 ECONNRESET 错误,解决该问题的唯一方法似乎是重新部署该函数。有什么想法如何进一步调试这个吗?

编辑:

似乎很多时候发生这种情况,当我尝试再次部署该函数时,它会出错,并且我必须运行部署两次。有东西挂着还是什么?

enter image description here

最佳答案

2017 年 5 月 9 日更新

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

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

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!

<小时/>

旧帖子如下:

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

我举报了ECONNRESET issue with cloud functions to Google Support (如果您在这种情况下也得到了 ECONNRESET,但在其他情况下没有得到 ECONNRESET,您可能会加注星号),他们回复说“不会修复”,该行为是预期的。 Google 支持人员表示,API 客户端库用于连接的套接字会在几分钟后超时,然后当您的云功能尝试再次使用它时,您会收到 ECONNRESET。他们建议在初始化存储 API 时添加 autoRetry:true,但这没有帮助。

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

所以我写了npm:pipe-to-storage返回一个重试的 promise ,检查 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);

另请参阅How do I read the contents of a new cloud storage file of type .json from within a cloud function?

关于firebase - Google Cloud Functions 出现 ECONNRESET 错误,直到我重新部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43058274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com