mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 00:43:49 +01:00
box: fix multipart upload giving "parts_mismatch" error #97
This commit is contained in:
parent
40f24e0ea3
commit
ee13ea74f1
@ -97,7 +97,8 @@ func (o *Object) commitUpload(SessionID string, parts []api.Part, modTime time.T
|
|||||||
request.Attributes.ContentCreatedAt = api.Time(modTime)
|
request.Attributes.ContentCreatedAt = api.Time(modTime)
|
||||||
var body []byte
|
var body []byte
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
const maxTries = 10
|
maxTries := fs.Config.LowLevelRetries
|
||||||
|
const defaultDelay = 10
|
||||||
var tries int
|
var tries int
|
||||||
outer:
|
outer:
|
||||||
for tries = 0; tries < maxTries; tries++ {
|
for tries = 0; tries < maxTries; tries++ {
|
||||||
@ -109,30 +110,40 @@ outer:
|
|||||||
body, err = rest.ReadBody(resp)
|
body, err = rest.ReadBody(resp)
|
||||||
return shouldRetry(resp, err)
|
return shouldRetry(resp, err)
|
||||||
})
|
})
|
||||||
|
delay := defaultDelay
|
||||||
|
why := "unknown"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
// Sometimes we get 400 Error with
|
||||||
}
|
// parts_mismatch immediately after uploading
|
||||||
delay := 1
|
// the last part. Ignore this error and wait.
|
||||||
switch resp.StatusCode {
|
if boxErr, ok := err.(*api.Error); ok && boxErr.Code == "parts_mismatch" {
|
||||||
case http.StatusOK, http.StatusCreated:
|
why = err.Error()
|
||||||
break outer
|
} else {
|
||||||
case http.StatusAccepted:
|
return nil, err
|
||||||
delayString := resp.Header.Get("Retry-After")
|
}
|
||||||
if delayString != "" {
|
} else {
|
||||||
delay, err = strconv.Atoi(delayString)
|
switch resp.StatusCode {
|
||||||
if err != nil {
|
case http.StatusOK, http.StatusCreated:
|
||||||
fs.Debugf(o, "Couldn't decode Retry-After header %q: %v", delayString, err)
|
break outer
|
||||||
delay = 1
|
case http.StatusAccepted:
|
||||||
}
|
why = "not ready yet"
|
||||||
|
delayString := resp.Header.Get("Retry-After")
|
||||||
|
if delayString != "" {
|
||||||
|
delay, err = strconv.Atoi(delayString)
|
||||||
|
if err != nil {
|
||||||
|
fs.Debugf(o, "Couldn't decode Retry-After header %q: %v", delayString, err)
|
||||||
|
delay = defaultDelay
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return nil, errors.Errorf("unknown HTTP status return %q (%d)", resp.Status, resp.StatusCode)
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
return nil, errors.Errorf("unknown HTTP status return %q (%d)", resp.Status, resp.StatusCode)
|
|
||||||
}
|
}
|
||||||
fs.Debugf(o, "commit multipart upload failed %d/%d - trying again in %d seconds", tries+1, maxTries, delay)
|
fs.Debugf(o, "commit multipart upload failed %d/%d - trying again in %d seconds (%s)", tries+1, maxTries, delay, why)
|
||||||
time.Sleep(time.Duration(delay) * time.Second)
|
time.Sleep(time.Duration(delay) * time.Second)
|
||||||
}
|
}
|
||||||
if tries >= maxTries {
|
if tries >= maxTries {
|
||||||
return nil, errors.New("too many tries to commit multipart upload")
|
return nil, errors.New("too many tries to commit multipart upload - increase --low-level-retries")
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(body, &result)
|
err = json.Unmarshal(body, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user