Skip to content

Commit

Permalink
refactor(provider): add retry for connection reset by peer error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-Zhang9309 committed Dec 26, 2024
1 parent c5fb0d8 commit 67949ce
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions huaweicloud/config/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ func (lrt *LogRoundTripper) RoundTrip(request *http.Request) (*http.Response, er
retry++
}

// retry connection reset by peer error
retry = 1
for err != nil && strings.Contains(err.Error(), "connection reset by peer") {
if retry > lrt.MaxRetries {
log.Printf("[DEBUG] [%s] connection error, retries exhausted. Aborting", logId)
err = fmt.Errorf("connection error, retries exhausted. Aborting. Last error was: %s", err)
return nil, err
}

log.Printf("[DEBUG] [%s] connection error, retry number %d: %s", logId, retry, err)

//lintignore:R018

Check warning on line 124 in huaweicloud/config/logger.go

View workflow job for this annotation

GitHub Actions / golangci

comment-spacings: no space between comment delimiter and comment text (revive)
time.Sleep(retryTimeout(retry))
response, err = lrt.Rt.RoundTrip(request)
retry++
}

return response, err
}

Expand Down

0 comments on commit 67949ce

Please sign in to comment.