b2: Fix handling of token expiry #420

Found with --b2-test-mode expire_some_account_authorization_tokens
This commit is contained in:
Nick Craig-Wood 2016-07-01 11:47:42 +01:00
parent 6f3897ce2c
commit cbebefebc4
2 changed files with 10 additions and 16 deletions

View file

@ -44,13 +44,10 @@ const (
// Globals // Globals
var ( var (
minChunkSize = fs.SizeSuffix(100E6) minChunkSize = fs.SizeSuffix(100E6)
chunkSize = fs.SizeSuffix(96 * 1024 * 1024) chunkSize = fs.SizeSuffix(96 * 1024 * 1024)
uploadCutoff = fs.SizeSuffix(200E6) uploadCutoff = fs.SizeSuffix(200E6)
errorAuthTokenExpired = errors.New("b2 auth token expired") b2TestMode = pflag.StringP("b2-test-mode", "", "", "A flag string for X-Bz-Test-Mode header.")
errorUploadTokenExpired = errors.New("b2 upload token expired")
errorUploadPartTokenExpired = errors.New("b2 upload part token expired")
b2TestMode = pflag.StringP("b2-test-mode", "", "", "A flag string for X-Bz-Test-Mode header.")
) )
// Register with Fs // Register with Fs
@ -161,9 +158,8 @@ func (f *Fs) shouldRetryNoReauth(resp *http.Response, err error) (bool, error) {
// shouldRetry returns a boolean as to whether this resp and err // shouldRetry returns a boolean as to whether this resp and err
// deserve to be retried. It returns the err as a convenience // deserve to be retried. It returns the err as a convenience
func (f *Fs) shouldRetry(resp *http.Response, err error) (bool, error) { func (f *Fs) shouldRetry(resp *http.Response, err error) (bool, error) {
if err == nil && resp != nil && resp.StatusCode == 401 { if resp != nil && resp.StatusCode == 401 {
err = errorAuthTokenExpired fs.Debug(f, "Unauthorized: %v", err)
fs.Debug(f, "%v", err)
// Reauth // Reauth
authErr := f.authorizeAccount() authErr := f.authorizeAccount()
if authErr != nil { if authErr != nil {
@ -1198,9 +1194,8 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo) (err error) {
// Don't retry, return a retry error instead // Don't retry, return a retry error instead
err = o.fs.pacer.CallNoRetry(func() (bool, error) { err = o.fs.pacer.CallNoRetry(func() (bool, error) {
resp, err := o.fs.srv.CallJSON(&opts, nil, &response) resp, err := o.fs.srv.CallJSON(&opts, nil, &response)
if err == nil && resp != nil && resp.StatusCode == 401 { if resp != nil && resp.StatusCode == 401 {
err = errorUploadTokenExpired fs.Debug(o, "Unauthorized: %v", err)
fs.Debug(o, "%v", err)
// Invalidate this Upload URL // Invalidate this Upload URL
upload = nil upload = nil
// Refetch upload URLs // Refetch upload URLs

View file

@ -178,9 +178,8 @@ func (up *largeUpload) transferChunk(part int64, body []byte) error {
var response api.UploadPartResponse var response api.UploadPartResponse
resp, err := up.f.srv.CallJSON(&opts, nil, &response) resp, err := up.f.srv.CallJSON(&opts, nil, &response)
if err == nil && resp != nil && resp.StatusCode == 401 { if resp != nil && resp.StatusCode == 401 {
err = errorUploadPartTokenExpired fs.Debug(up.o, "Unauthorized: %v", err)
fs.Debug(up.o, "%v", err)
// Refetch upload part URLs and ditch this current one // Refetch upload part URLs and ditch this current one
up.clearUploadURL() up.clearUploadURL()
return true, err return true, err