首页 > 解决方案 > 如何解决 gcloud 崩溃 (ReadTimeout):HTTPSConnectionPool(host='cloudfunctions.googleapis.com', port=443):读取超时。(读取超时=300)

问题描述

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

gcloud functions call function_name

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

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

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

标签: google-cloud-platformgoogle-cloud-functionsgcloud

解决方案


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

我创建了一个简单的 Golang 云函数:

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}

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

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 call300 秒后超时,这是不可配置的。

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


推荐阅读