Add 'isValidRetry()' to retry for only network level errors
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"time"
|
||||
@@ -31,6 +32,24 @@ import (
|
||||
"github.com/minio-io/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
// isValidRetry - check if we should retry for the given error sequence
|
||||
func isValidRetry(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
// DNSError, Network Operation error
|
||||
switch e := iodine.ToError(err).(type) {
|
||||
case *net.DNSError:
|
||||
return true
|
||||
case *net.OpError:
|
||||
switch e.Op {
|
||||
case "read", "write", "dial":
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// StartBar -- instantiate a progressbar
|
||||
func startBar(size int64) *pb.ProgressBar {
|
||||
bar := pb.New(int(size))
|
||||
|
||||
@@ -58,10 +58,10 @@ func doList(clnt client.Client, urlStr string) (string, error) {
|
||||
var items []*client.Item
|
||||
|
||||
items, err = clnt.List()
|
||||
if err != nil {
|
||||
if err != nil && isValidRetry(err) {
|
||||
console.Infof("Retrying ...")
|
||||
}
|
||||
for i := 1; i <= globalMaxRetryFlag && err != nil; i++ {
|
||||
for i := 1; i <= globalMaxRetryFlag && err != nil && isValidRetry(err); i++ {
|
||||
items, err = clnt.List()
|
||||
console.Errorf(" %d", i)
|
||||
// Progressively longer delays
|
||||
@@ -72,6 +72,7 @@ func doList(clnt client.Client, urlStr string) (string, error) {
|
||||
msg := fmt.Sprintf("\nmc: listing objects for URL [%s] failed with following reason: [%s]\n", urlStr, iodine.ToError(err))
|
||||
return msg, err
|
||||
}
|
||||
console.Infoln()
|
||||
printItems(items)
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -86,5 +86,6 @@ func doMakeBucketCmd(manager clientManager, u string, debug bool) (string, error
|
||||
msg := fmt.Sprintf("\nmc: Creating bucket failed for URL [%s] with following reason: [%s]\n", u, iodine.ToError(err))
|
||||
return msg, err
|
||||
}
|
||||
console.Infoln()
|
||||
return "", nil
|
||||
}
|
||||
|
||||
@@ -42,13 +42,12 @@ func (c *s3Client) List() (items []*client.Item, err error) {
|
||||
return items, nil
|
||||
default:
|
||||
if bucket == "" {
|
||||
items, err = c.listBuckets()
|
||||
} else {
|
||||
// List all objects matching the key prefix
|
||||
items, err = c.listObjectsInternal(bucket, "", objectPrefix, "", globalMaxKeys)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
return c.listBuckets()
|
||||
}
|
||||
// List all objects matching the key prefix
|
||||
items, err = c.listObjectsInternal(bucket, "", objectPrefix, "", globalMaxKeys)
|
||||
if err != nil {
|
||||
return nil, iodine.New(err, nil)
|
||||
}
|
||||
// even if items are equal to '0' is valid case
|
||||
return items, nil
|
||||
|
||||
Reference in New Issue
Block a user