{"record":{"id":"92ba08455d521f28","repo":"AlistGo/alist","slug":"upload-failed-after-d-retries-due-to-server-error-92ba08","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/util.go","lineNumber":348,"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, stream.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(\"[Cloudreve-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(stream.GetSize()))\n\t\t}\n\t}\n\t// 上传成功发送回调请求\n\treturn d.request(http.MethodPost, \"/callback/onedrive/finish/\"+u.SessionID, func(req *resty.Request) {\n\t\treq.SetBody(\"{}\")","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/cloudreve/util.go#L330-L366","documentation":"Fatal retry exhaustion in Cloudreve's OneDrive-mediated upload (upOneDrive). Chunks are PUT directly to the OneDrive upload session URL; HTTP 500-504 responses are retried with exponential backoff. When retries exceed maxRetries, the loop aborts with this message, embedding the last HTTP status code.","triggerScenarios":"Every chunk PUT to the OneDrive upload URL returns a 5xx status (500-504) more than maxRetries times consecutively: OneDrive service degradation, the upload session expired server-side (some 5xx masks are actually session-invalid), or an intermediary proxy manufacturing 5xx responses.","commonSituations":"OneDrive outages or throttling during large uploads; a reverse proxy in front of Cloudreve timing out and returning 502/504 per chunk; slow networks where each chunk exceeds proxy timeouts.","solutions":["Retry the whole upload after a wait — transient OneDrive 5xx storms usually clear","Increase proxy read/write timeouts (or bypass the proxy for upload URLs) so chunk PUTs are not converted into 504s","Check OneDrive service status and the Cloudreve session's validity; restart the upload to get a fresh session if it expired","Raise maxRetries or use smaller chunks so each retry window is shorter"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// pre-flight: confirm the OneDrive session URL is alive with a cheap 0-byte request if supported, and check proxy timeouts > chunk transfer time","typeGuard":null,"tryCatchPattern":"if err := d.upOneDrive(ctx, stream, u, up); err != nil {\n    if strings.Contains(err.Error(), \"retries due to server errors\") {\n        // session may be stale or OneDrive degraded: get a fresh session and retry once\n        u2, err2 := d.getUploadInfo(ctx, stream)\n        if err2 == nil {\n            err = d.upOneDrive(ctx, stream, u2, up)\n        }\n    }\n}","preventionTips":["Set reverse-proxy timeouts above worst-case chunk upload duration","Retry whole uploads (fresh session) rather than extending per-chunk retries indefinitely","Watch OneDrive status pages during incident windows and defer bulk uploads"],"tags":["alist","cloudreve","onedrive","upload","retry","http-5xx"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}