forked from TrueCloudLab/rclone
hubic: retry auth fetching if it fails to make hubic more reliable
This commit is contained in:
parent
c644241392
commit
164d1e05ca
1 changed files with 12 additions and 5 deletions
|
@ -2,7 +2,9 @@ package hubic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/ncw/rclone/fs"
|
||||||
"github.com/ncw/swift"
|
"github.com/ncw/swift"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,12 +23,17 @@ func newAuth(f *Fs) *auth {
|
||||||
// Request constructs a http.Request for authentication
|
// Request constructs a http.Request for authentication
|
||||||
//
|
//
|
||||||
// returns nil for not needed
|
// returns nil for not needed
|
||||||
func (a *auth) Request(*swift.Connection) (*http.Request, error) {
|
func (a *auth) Request(*swift.Connection) (r *http.Request, err error) {
|
||||||
err := a.f.getCredentials()
|
const retries = 10
|
||||||
if err != nil {
|
for try := 1; try <= retries; try++ {
|
||||||
return nil, err
|
err = a.f.getCredentials()
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
fs.Debugf(a.f, "retrying auth request %d/%d: %v", try, retries, err)
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response parses the result of an http request
|
// Response parses the result of an http request
|
||||||
|
|
Loading…
Add table
Reference in a new issue