Skip to content

Commit

Permalink
api: Retry only request body is seekable
Browse files Browse the repository at this point in the history
It doesn't make sense to retry a HTTP request when its body is not
seekable. Req Body can be delivered by a developer such as in
PutObject() API.
  • Loading branch information
vadmeste committed Sep 20, 2017
1 parent 4e0f567 commit 8990873
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,20 @@ var successStatus = []int{
func (c Client) executeMethod(method string, metadata requestMetadata) (res *http.Response, err error) {
var isRetryable bool // Indicates if request can be retried.
var bodySeeker io.Seeker // Extracted seeker from io.Reader.
var reqRetry = MaxRetry // Indicates how many times we can retry the request

if metadata.contentBody != nil {
// Check if body is seekable then it is retryable.
bodySeeker, isRetryable = metadata.contentBody.(io.Seeker)
switch bodySeeker {
case os.Stdin, os.Stdout, os.Stderr:
isRetryable = false
}
// Retry only when reader is seekable
if !isRetryable {
reqRetry = 1
}

// Figure out if the body can be closed - if yes
// we will definitely close it upon the function
// return.
Expand All @@ -522,7 +529,7 @@ func (c Client) executeMethod(method string, metadata requestMetadata) (res *htt
// Blank indentifier is kept here on purpose since 'range' without
// blank identifiers is only supported since go1.4
// https://golang.org/doc/go1.4#forrange.
for range c.newRetryTimer(MaxRetry, DefaultRetryUnit, DefaultRetryCap, MaxJitter, doneCh) {
for range c.newRetryTimer(reqRetry, DefaultRetryUnit, DefaultRetryCap, MaxJitter, doneCh) {
// Retry executes the following function body if request has an
// error until maxRetries have been exhausted, retry attempts are
// performed after waiting for a given period of time in a
Expand Down

0 comments on commit 8990873

Please sign in to comment.