在我重新部署之前出现 ECONNRESET 错误的 Google Cloud Functions [英] Google Cloud Functions with ECONNRESET errors until I redeploy

查看:26
本文介绍了在我重新部署之前出现 ECONNRESET 错误的 Google Cloud Functions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Google Cloud Functions 来:

I'm using Google Cloud Functions to:

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

不幸的是,我在第 4 步中反复遇到 ECONNRESET 错误,修复它的唯一方法似乎是重新部署该函数.有什么想法可以进一步调试吗?

Unfortunately I'm getting ECONNRESET errors repeatedly on step 4, and the only way to fix it seems to be to redeploy the function. Any ideas how to further debug this?

似乎很多次发生这种情况,当我尝试再次部署该功能时,它会出错,我必须运行两次部署.是挂了还是什么?

It seems like many times when this happens, when I try to deploy the function again, it errors, and I have to run the deploy twice. Is something hanging or something?

推荐答案

2017 年 5 月 9 日更新

根据这个帖子,谷歌cloud nodejs API 开发人员对初始化时使用的默认值进行了一些更改,这应该可以解决这些 ECONNRESET 套接字问题.

Update May 9 2017

According to this thread, the google cloud nodejs API developers have made some changes to the defaults that are used when initializing that should solve these ECONNRESET socket issues.

来自@stephen++ on github GoogleCloudPlatform/google-cloud-node issue 2254:

From @stephen++ on github GoogleCloudPlatform/google-cloud-node issue 2254:

我们在 Cloud Function 中默认禁用了永久代理环境.如果您卸载并重新安装 @google-cloud/storage,您将自动选择新行为.感谢所有的调试有用,大家好!

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 次重试次数太多了.


Older Post Follows:

The solution for me to similar ECONNRESET issues using storage on the cloud functions platform was to use npm:promise-retry, but set up your own retry strategy because the default of 10 retries is too many.

我向 Google 支持报告了一个 ECONNRESET 云功能问题(如果您在这种情况下也会得到 ECONNRESET,但在其他情况下不会),他们回答说不会修复"该行为是预期的.谷歌支持表示 API 客户端库用于连接的套接字会在几分钟后超时,然后当您的云功能尝试再次使用它时,您将获得 ECONNRESET.他们建议在初始化存储 API 时添加 autoRetry:true,但这并没有帮助.

I reported an ECONNRESET issue with cloud functions to Google Support (which you might star if you are also getting ECONNRESET in this context but not in other contexts) and they replied with a "won't fix" that the behavior is expected. Google support said the socket that the API client library uses to connect times out after a few minutes, and then when your cloud function tries to use it again you get ECONNRESET. They recommended adding autoRetry:true when initializing the storage API, but that did not help.

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

The ECONNRESETs happen on the read side too. In both read and write cases promise-retry helps, and most of the time with only 1 retry needed to reset the bad socket.

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

So I wrote npm:pipe-to-storage to return a promise to do the retries, check md5, etc., but I haven't tested it with binary data, only text, so I don't know if you could use it with image files. The calls would look like this:

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);

另请参阅 如何从云函数中读取 .json 类型的新云存储文件的内容?

这篇关于在我重新部署之前出现 ECONNRESET 错误的 Google Cloud Functions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆