mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-05 17:52:38 +00:00
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:
parent
bc91f6be60
commit
c727bc458c
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user