{"record":{"id":"ce2a57b7e0d4ba2a","repo":"AlistGo/alist","slug":"upload-failed-after-d-retries-due-to-server-error-ce2a57","errorCode":null,"errorMessage":"upload failed after %d retries due to server errors, error %d","messagePattern":"upload failed after (.+?) retries due to server errors, error (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/cloudreve_v4/util.go","lineNumber":366,"sourceCode":"\t\t\treturn err\n\t\t}\n\t\treq = req.WithContext(ctx)\n\t\treq.ContentLength = byteSize\n\t\t// req.Header.Set(\"Content-Length\", strconv.Itoa(int(byteSize)))\n\t\treq.Header.Set(\"Content-Range\", fmt.Sprintf(\"bytes %d-%d/%d\", finish, finish+byteSize-1, file.GetSize()))\n\t\treq.Header.Set(\"User-Agent\", d.getUA())\n\t\tfinish += byteSize\n\t\tres, err := base.HttpClient.Do(req)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\t// https://learn.microsoft.com/zh-cn/onedrive/developer/rest-api/api/driveitem_createuploadsession\n\t\tswitch {\n\t\tcase res.StatusCode >= 500 && res.StatusCode <= 504:\n\t\t\tretryCount++\n\t\t\tif retryCount > maxRetries {\n\t\t\t\tres.Body.Close()\n\t\t\t\treturn fmt.Errorf(\"upload failed after %d retries due to server errors, error %d\", maxRetries, res.StatusCode)\n\t\t\t}\n\t\t\tbackoff := time.Duration(1<<retryCount) * time.Second\n\t\t\tutils.Log.Warnf(\"[CloudreveV4-OneDrive] server errors %d while uploading, retrying after %v...\", res.StatusCode, backoff)\n\t\t\ttime.Sleep(backoff)\n\t\tcase res.StatusCode != 201 && res.StatusCode != 202 && res.StatusCode != 200:\n\t\t\tdata, _ := io.ReadAll(res.Body)\n\t\t\tres.Body.Close()\n\t\t\treturn errors.New(string(data))\n\t\tdefault:\n\t\t\tres.Body.Close()\n\t\t\tretryCount = 0\n\t\t\tfinish += byteSize\n\t\t\tup(float64(finish) * 100 / float64(file.GetSize()))\n\t\t}\n\t}\n\t// 上传成功发送回调请求\n\treturn d.request(http.MethodPost, \"/callback/onedrive/\"+u.SessionID+\"/\"+u.CallbackSecret, func(req *resty.Request) {\n\t\treq.SetBody(\"{}\")","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/cloudreve_v4/util.go#L348-L384","documentation":"Fatal retry exhaustion in Cloudreve v4's OneDrive-mediated upload (upOneDrive). Chunk PUTs go straight to the OneDrive session URL; HTTP 500-504 are retried with exponential backoff, and once retries exceed maxRetries the loop aborts with this message embedding the last status code.","triggerScenarios":"Every chunk PUT returns 500-504 more than maxRetries times consecutively: OneDrive degradation/throttling, an expired upload session surfacing as 5xx, or an intermediary proxy synthesizing 502/504 for slow chunk uploads.","commonSituations":"Large-file uploads during OneDrive incidents; reverse proxies with tight timeouts cutting long chunk PUTs; sessions going stale on very slow connections.","solutions":["Retry the whole upload later — transient 5xx bursts normally clear","Lengthen or remove proxy timeouts on the upload path","If the session expired, restart the upload for a fresh OneDrive upload session","Reduce chunk size or raise maxRetries to shorten each retry window"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-flight: ensure chunk size and proxy timeouts are compatible with the OneDrive session lifetime","typeGuard":null,"tryCatchPattern":"if err := d.upOneDrive(ctx, file, u, up); err != nil {\n    if strings.Contains(err.Error(), \"retries due to server errors\") {\n        u2, err2 := d.getUploadInfo(ctx, file) // fresh session, single retry\n        if err2 == nil {\n            err = d.upOneDrive(ctx, file, u2, up)\n        }\n    }\n}","preventionTips":["Raise proxy timeouts above worst-case chunk PUT duration","Defer bulk uploads during OneDrive incidents","Refresh upload sessions for very large files instead of extending retries"],"tags":["alist","cloudreve-v4","onedrive","upload","retry","http-5xx"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}