在我重新部署之前,Google Cloud会发生ECONNRESET错误 [英] Google Cloud Functions with ECONNRESET errors until I redeploy

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

问题描述

使用Google云端函数:


  1. 观看新的Firebase条目

  2. 下载Firebase条目中引用的文件

  3. 根据该文件生成缩略图。

  4. 将缩略图上传到云存储桶。

不幸的是我在步骤4中重复出现 ECONNRESET 错误,只有这样才能解决它似乎是重新部署的功能。任何想法如何进一步调试呢?

编辑:

似乎很多时候发生这种情况,当我尝试再次部署函数时,它的错误,我必须运行两次部署。是挂什么的?



< img src =https://i.stack.imgur.com/FbJoj.pngalt =在这里输入图片描述>

解决方案

更新2017年5月9日



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

从github上的@ stephen ++ GoogleCloudPlatform / google-cloud-node issue 2254:

lockquote

我们已经在Cloud Function
环境中默认禁用永久代理。如果您取消并重新安装@ google-cloud / storage,您
将自动提取新行为。感谢所有
帮助调试,每个人!







遵循:

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

我报告了云功能的 ECONNRESET问题Google支持(如果您在此环境中获得了ECONNRESET,但在其他环境中获得ECONNRESET,则可能会出现此问题),并回答说不会修复该行为是预期的。 Google支持人员表示,API客户端库在几分钟后用来连接超时的套接字,然后当您的云功能尝试再次使用它时,您将获得ECONNRESET。他们建议在初始化存储API时添加 autoRetry:true ,但这没有帮助。

ECONNRESETs也在读取方面发生。在读写情况下, promise-retry 都有帮助,而且大多数情况下只需要1次重试就可以重新设置错误的套接字。所以我写了 npm:pipe-to-storage 返回一个承诺来执行重试,检查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(//下一步);

另见如何读取新的云存储文件的内容在云端函数中输入.json?


I'm using Google Cloud Functions to:

  1. Watch for a new Firebase entry
  2. Download a file that's referenced in the Firebase entry
  3. Generate a thumbnail based on that file.
  4. Upload the thumbnail to the cloud bucket.

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?

Edit:

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?

解决方案

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.

From @stephen++ on github GoogleCloudPlatform/google-cloud-node issue 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!


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.

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.

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.

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

See also How do I read the contents of a new cloud storage file of type .json from within a cloud function?

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

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