{"record":{"id":"b9256fde332cb813","repo":"subhra74/xdm","slug":"maxretryfailed","errorCode":"MaxRetryFailed","errorMessage":"Max retry exceeded","messagePattern":"Max retry exceeded","errorType":"error_code","errorClass":"DownloadException","httpStatus":null,"severity":"error","filePath":"app/XDM/XDM.Core/Downloader/Progressive/PieceGrabber.cs","lineNumber":116,"sourceCode":"                    catch (HttpException e)\r\n                    {\r\n                        var status = e.StatusCode;\r\n                        if (Enum.IsDefined(typeof(HttpStatusCode), status))\r\n                        {\r\n                            throw new DownloadException(ErrorCode.InvalidResponse,\r\n                                \"Invalid response: \" + e.Message, e);\r\n                        }\r\n                    }\r\n                    catch (Exception e)\r\n                    {\r\n                        if (e is KeyNotFoundException || this.CancellationToken.IsCancellationRequested) return;\r\n                        if (e is AssembleFailedException || e is NonRetriableException || e is OperationCanceledException) throw;\r\n                        Log.Debug(e, \"Error in PieceGrabber inner block - swallowing error - isCancelled: \" + this.cancellationTokenSource.IsCancellationRequested);\r\n                    }\r\n                    timesRetried++;\r\n                    if (timesRetried > Config.Instance.MaxRetry)\r\n                    {\r\n                        throw new DownloadException(ErrorCode.MaxRetryFailed, \"Max retry exceeded\");\r\n                    }\r\n                    if (connectPhase)\r\n                    {\r\n                        sleep(Config.Instance.RetryDelay * 1000);\r\n                        CancellationToken.ThrowIfCancellationRequested();\r\n                        //await Task.Delay(Config.Instance.RetryDelay * 1000,\r\n                        //    this.CancellationToken).ConfigureAwait(false);\r\n                    }\r\n                }\r\n            }\r\n            catch (Exception e)\r\n            {\r\n                if (e is KeyNotFoundException || this.CancellationToken.IsCancellationRequested)\r\n                {\r\n                    return;\r\n                }\r\n                Log.Debug(e, \"Error in PieceGrabber outer block\");\r\n                if (this.pieceId != null)\r","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/subhra74/xdm/blob/1ca5a25aae007826c859c81bea494e7c102e1242/app/XDM/XDM.Core/Downloader/Progressive/PieceGrabber.cs#L98-L134","documentation":"PieceGrabber retries a failing download loop up to Config.Instance.MaxRetry times. Each caught failure increments timesRetried and, when the counter exceeds MaxRetry, the grabber throws DownloadException with ErrorCode.MaxRetryFailed. It means the piece repeatedly failed to connect or transfer and the library has given up retrying.","triggerScenarios":"The inner download block throws a retryable exception (network drop, connection reset, timeout) more than MaxRetry consecutive times inside PieceGrabber's loop; cancellation and non-retriable exceptions (AssembleFailedException, NonRetriableException, OperationCanceledException) are rethrown instead and never reach this path.","commonSituations":"Flaky or throttled network connections, servers that keep rejecting range requests, MaxRetry configured too low (default small) on unreliable links, firewalls/proxies intermittently killing persistent connections.","solutions":["Increase Config.Instance.MaxRetry to allow more attempts on unstable networks.","Increase Config.Instance.RetryDelay to give the server/network time to recover between attempts.","Check network stability (proxy, VPN, firewall) and retry the download manually.","Wrap download orchestration to catch MaxRetryFailed and restart the download from persisted pieces."],"exampleFix":"// before\nvar cfg = Config.Instance; // MaxRetry = 3\n// after\nvar cfg = Config.Instance;\ncfg.MaxRetry = 10;      // tolerate unstable links\ncfg.RetryDelay = 5;     // seconds between attempts","handlingStrategy":"retry","validationCode":"// before starting\nif (Config.Instance.MaxRetry < 5) Config.Instance.MaxRetry = 5;\nif (!NetworkInterface.GetIsNetworkAvailable()) throw new InvalidOperationException(\"No network\");","typeGuard":null,"tryCatchPattern":"try { downloader.Download(); }\ncatch (DownloadException e) when (e.ErrorCode == ErrorCode.MaxRetryFailed) {\n    Log.Warn(\"Giving up after max retries\");\n    ScheduleRetryWithBackoff();\n}","preventionTips":["Configure MaxRetry >= 5 for mobile/unstable links","Set a sensible RetryDelay (3-10s)","Monitor network availability before/ during downloads","Persist piece state so restarts resume, not restart"],"tags":["network","retry","download"],"backgroundTag":"request-timeout","analyzedSha":"1ca5a25aae007826c859c81bea494e7c102e1242","analyzedAt":"2026-09-13T20:37:40.968Z","contentChangedAt":"2026-09-13T20:37:40.968Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}