Handle operation timeouts, if it's the gcp api that's timing out. (#3159)

Signed-off-by: Modular Magician <magic-modules@google.com>
This commit is contained in:
The Magician 2019-03-01 12:03:36 -08:00 committed by Nathan McKinley
parent bc91f6be60
commit c727bc458c
2 changed files with 11 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"time"
"github.com/hashicorp/terraform/helper/logging"
"github.com/hashicorp/terraform/helper/pathorcontents"
@ -114,6 +115,10 @@ func (c *Config) loadAndValidate() error {
client := oauth2.NewClient(context.Background(), tokenSource)
client.Transport = logging.NewTransport("Google", client.Transport)
// Each individual request should return within 30s - timeouts will be retried.
// This is a timeout for, e.g. a single GET request of an operation - not a
// timeout for the maximum amount of time a logical request can take.
client.Timeout, _ = time.ParseDuration("30s")
terraformVersion := httpclient.UserAgentString()
providerVersion := fmt.Sprintf("terraform-provider-google/%s", version.ProviderVersion)

View File

@ -7,6 +7,7 @@ import (
"encoding/hex"
"fmt"
"log"
"net/url"
"strings"
"time"
@ -343,6 +344,11 @@ func isRetryableError(err error) bool {
if gerr, ok := err.(*googleapi.Error); ok && (gerr.Code == 409 || gerr.Code == 429 || gerr.Code == 500 || gerr.Code == 502 || gerr.Code == 503) {
return true
}
// These operations are always hitting googleapis.com - they should rarely
// time out, and if they do, that timeout is retryable.
if urlerr, ok := err.(*url.Error); ok && urlerr.Timeout() {
return true
}
return false
}