Skip to content

Commit

Permalink
Clean up retriable error syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisst committed Mar 20, 2019
1 parent e5cc236 commit 7b808b5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions third_party/terraform/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,21 +350,22 @@ func retryTimeDuration(retryFunc func() error, duration time.Duration) error {
}

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) {
if gerr.Code == 409 && !strings.Contains(gerr.Body, "operationInProgress") {
// 409's are retried because cloud sql throws a 409 when concurrent calls are made, however we only
// want to retry sql conflicts and not actual 409 conflicts such as name already exists. Until we
// stop using the sql client we must check the error string to determine if it's retriable
// See https://github.com/terraform-providers/terraform-provider-google/issues/3279
return false
}
if gerr, ok := err.(*googleapi.Error); ok && (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
}
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 409 && strings.Contains(gerr.Body, "operationInProgress") {
// 409's are retried because cloud sql throws a 409 when concurrent calls are made.
// The only way right now to determine it is a SQL 409 due to concurrent calls is to
// look at the contents of the error message.
// See https://github.com/terraform-providers/terraform-provider-google/issues/3279
return true
}

return false
}

Expand Down

0 comments on commit 7b808b5

Please sign in to comment.