Skip to content

Commit

Permalink
Make connection reset error pred more generic, debug logs (GoogleClou…
Browse files Browse the repository at this point in the history
…dPlatform#3143)

* make connection reset error pred more generic, debug logs

* fmt

* import
  • Loading branch information
emilymye authored and Nathan Klish committed May 18, 2020
1 parent 90be373 commit e953bea
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions third_party/terraform/utils/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"strings"

"golang.org/x/oauth2"
"google.golang.org/api/googleapi"
)

Expand Down Expand Up @@ -67,18 +68,25 @@ func isIoEOFError(err error) (bool, string) {
return false, ""
}

const connectionResetByPeerErr = "connection reset by peer"
const connectionResetByPeerErr = ": connection reset by peer"

func isConnectionResetNetworkError(err error) (bool, string) {
neterr, ok := err.(*net.OpError)
if !ok {
if urlerr, urlok := err.(*url.Error); urlok {
wrappedErr := urlerr.Unwrap()
neterr, ok = wrappedErr.(*net.OpError)
if strings.HasSuffix(err.Error(), connectionResetByPeerErr) {
//TODO(emilymye, TPG#3957): Remove these debug logs
log.Printf("[DEBUG] Found connection reset by peer error of type %T", err)
switch err.(type) {
case *url.Error:
case *net.OpError:
log.Printf("[DEBUG] Connection reset error returned from net/url")
case *googleapi.Error:
log.Printf("[DEBUG] Connection reset error wrapped by googleapi.Error")
case *oauth2.RetrieveError:
log.Printf("[DEBUG] Connection reset error wrapped by oauth2")
default:
log.Printf("[DEBUG] Connection reset error wrapped by %T", err)
}
}
if ok && neterr.Err.Error() == connectionResetByPeerErr {
return true, fmt.Sprintf("Connection reset by peer")

return true, fmt.Sprintf("reset connection")
}
return false, ""
}
Expand Down

0 comments on commit e953bea

Please sign in to comment.