Search code examples
google-cloud-platformgoogle-cloud-functionsgcloud

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


I receive the error when triggering a cloud function using the gcloud command from terminal:

gcloud functions call function_name

On the cloud function log page no error is shown and the task is finished with no problem, however, after the task is finished this error shows up on the terminal.

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

Note: my function time out is set to 540 second and it takes ~320 seconds to finish the job


Solution

  • I think the issue is that gcloud functions call times out after 300 seconds and is non-configurable for a longer timeout to match the Cloud Function.

    I created a simple 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")
    }
    

    And deployed it:

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

    Then I time'd it using gcloud functions call ${NAME} ...

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

    And this timed out:

    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
    

    NOTE 5m1s ~== 300s

    But, using 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)")
    

    Yields:

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

    NOTE 6m43s ~== 400s

    So, gcloud functions call times out after 300 seconds and this is non-configurable.

    Submitted an issue to Google's Issue Tracker.