【问题标题】:How to resolve gcloud crashed (ReadTimeout): HTTPSConnectionPool(host='cloudfunctions.googleapis.com', port=443): Read timed out. (read timeout=300)如何解决 gcloud 崩溃 (ReadTimeout):HTTPSConnectionPool(host='cloudfunctions.googleapis.com', port=443):读取超时。 (读取超时=300)
【发布时间】:2021-08-30 20:22:47
【问题描述】:

我在终端使用 gcloud 命令触发云功能时收到错误消息:

gcloud functions call function_name

在云功能日志页面上没有显示错误,任务完成没有问题,但是任务完成后,终端上显示此错误。

gcloud crashed (ReadTimeout): HTTPSConnectionPool(host='cloudfunctions.googleapis.com', port=443): Read timed out. (read timeout=300)

注意:我的函数超时设置为 540 秒,完成工作大约需要 320 秒

【问题讨论】:

  • 我想知道gcloud functions call超时是否是静态的(300s)?然后,您部署的函数是否具有更长的超时时间并不重要。你可以试试curl'ing 吗?
  • 或许curl --request GET --max-time 540 --header "Authorization: Bearer $(gcloud auth print-access-token)" $(gcloud functions describe ${NAME} --project=${PROJECT} --format="value(httpsTrigger.url)")
  • 尝试这个curl --request GET --max-time 540 --header "Authorization: Bearer $(gcloud auth print-access-token)" $(gcloud functions describe XXX --project=XXX --format="value(httpsTrigger.url)") 产生curl: no URL specified! 我在构造命令时遗漏了什么吗?同样在我原来的 gcloud 命令中,我传入了 --data 参数,我还需要将它包含在 curl 中吗?
  • 您可以单独运行嵌入的gcloud 命令来向自己证明它们都产生了合理的值。是的,抱歉,为任何 JSON 数据添加 -d '{ ....}' 并使用 --request POST 而不是 GET
  • 第一个命令 (gcloud auth ...) 获取访问令牌。第二个命令 (gcloud functions describe ...) 获取函数的端点。

标签: google-cloud-platform google-cloud-functions gcloud


【解决方案1】:

我认为问题在于 gcloud functions call 在 300 秒后超时,并且无法配置更长的超时以匹配云功能。

我创建了一个简单的 Golang Cloud Function:

func HelloFreddie(w http.ResponseWriter, r *http.Request) {
    log.Println("Sleeping")
    time.Sleep(400*time.Second)
    log.Println("Resuming")
    fmt.Fprint(w, "Hello Freddie")
}

并部署它:

gcloud functions deploy ${NAME} \
--region=${REGION} \
--allow-unauthenticated \
--entry-point="HelloFreddie" \
--runtime=go113 \
--source=${PWD} \
--timeout=520 \
--max-instances=1 \
--trigger-http \
--project=${PROJECT}

然后我使用gcloud functions call ${NAME} ...time'd 它

time \
  gcloud functions call ${NAME} \
  --region=${REGION} \
  --project=${PROJECT}

这超时了:

ERROR: gcloud crashed (ReadTimeout): HTTPSConnectionPool(host='cloudfunctions.googleapis.com', port=443): Read timed out. (read timeout=300)

real    5m1.079s
user    0m0.589s
sys     0m0.107s

注意 5m1s ~== 300s

但是,使用curl

time \
  curl \
  --request GET \
  --header "Authorization: Bearer $(gcloud auth print-access-token)" \
  $(\
    gcloud functions describe ${NAME} \
    --region=${REGION}
    --project=${PROJECT} \
    --format="value(httpsTrigger.url)")

产量:

Hello Freddie
real    6m43.048s
user    0m1.210s
sys     0m0.167s

注意 6m43s ~== 400s

所以,gcloud functions call 在 300 秒后超时,这是不可配置的。

向 Google 的问题跟踪器提交了 issue

【讨论】:

    猜你喜欢
    • 2020-01-19
    • 2021-01-01
    • 2021-04-26
    • 2017-09-04
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    相关资源
    最近更新 更多