Skip to content

Commit

Permalink
Retry on closed connection (#189)
Browse files Browse the repository at this point in the history
* retry-on-closed-connection

* add test for closed network connection

* update name of the test
  • Loading branch information
eminugurkenar authored Jul 21, 2020
1 parent 582a86d commit a4865c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,11 @@ func (c *customRetryer) ShouldRetry(req *request.Request) bool {
if errHasCode(req.Error, "InternalError") {
return true
}

if errContains(req.Error, "use of closed network connection") {
return true
}

return c.DefaultRetryer.ShouldRetry(req)
}

Expand Down Expand Up @@ -701,6 +706,21 @@ func errHasCode(err error, code string) bool {

}

func errContains(err error, msg string) bool {
if err == nil || msg == "" {
return false
}

var awsErr awserr.Error
if errors.As(err, &awsErr) {
if strings.Contains(awsErr.Error(), msg) {
return true
}
}

return false
}

// IsCancelationError reports whether given error is a storage related
// cancelation error.
func IsCancelationError(err error) bool {
Expand Down
4 changes: 4 additions & 0 deletions storage/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ func TestS3Retry(t *testing.T) {
name: "RequestError",
err: awserr.New(request.ErrCodeRequestError, "request error", nil),
},
{
name: "UseOfClosedNetworkConnection",
err: awserr.New(request.ErrCodeRequestError, "use of closed network connection", nil),
},
{
name: "RequestFailureRequestError",
err: awserr.NewRequestFailure(
Expand Down

0 comments on commit a4865c1

Please sign in to comment.