{"record":{"id":"800916b8e2a9eb62","repo":"subhra74/xdm","slug":"diskerror","errorCode":"DiskError","errorMessage":"Disk error :: {piece.Id}","messagePattern":"Disk error :: (.+?)","errorType":"error_code","errorClass":"NonRetriableException","httpStatus":null,"severity":"critical","filePath":"app/XDM/XDM.Core/Downloader/Progressive/PieceGrabber.cs","lineNumber":299,"sourceCode":"                            break;\r\n                        }\r\n                    }\r\n                    var x = sourceStream.Read(BUF, 0,\r\n                        (int)Math.Min(BUF.Length, remaining));\r\n                    this.CancellationToken.ThrowIfCancellationRequested();\r\n                    if (x == 0)\r\n                    {\r\n                        throw new DownloadException(ErrorCode.Generic, \"Unexpected EOF :: \" + piece.Id);\r\n                    }\r\n                    try\r\n                    {\r\n                        targetStream.Write(BUF, 0, x);\r\n                        count += x;\r\n                    }\r\n                    catch (IOException ioe)\r\n                    {\r\n                        Log.Debug(ioe, \"Disk error\");\r\n                        throw new NonRetriableException(ErrorCode.DiskError, \"Disk error :: \" + piece.Id, ioe);\r\n                    }\r\n                    if (this.CancellationToken.IsCancellationRequested) return;\r\n                    this.callback?.UpdateDownloadedBytesCount(this.pieceId, x);\r\n                    this.callback?.ThrottleIfNeeded();\r\n                }\r\n            }\r\n            finally\r\n            {\r\n#if !NET35\r\n                System.Buffers.ArrayPool<byte>.Shared.Return(BUF, false);\r\n#endif\r\n            }\r\n        }\r\n\r\n        private void CloseUnfinishedRequest(long count)\r\n        {\r\n            if (actualHttpResponseSize - count != 0)\r\n            {\r","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/subhra74/xdm/blob/1ca5a25aae007826c859c81bea494e7c102e1242/app/XDM/XDM.Core/Downloader/Progressive/PieceGrabber.cs#L281-L317","documentation":"In PieceGrabber.CopyWithFixedLength, writing downloaded bytes to the target stream raises an IOException (disk full, permission, hardware fault). The grabber logs it and wraps it as NonRetriableException with ErrorCode.DiskError since retrying a disk problem will not help.","triggerScenarios":"targetStream.Write throws IOException while copying a fixed-length piece - typically disk full, file locked by another process, or an I/O device error on the destination volume.","commonSituations":"Destination drive out of space during a large download, antivirus/backup tools locking the file, removable drive disconnecting, quota limits exceeded, bad sectors.","solutions":["Free disk space on the destination drive and restart the download.","Choose a different download destination on a healthy local volume.","Close programs locking the target file (antivirus, sync clients) or add an exclusion.","Run chkdsk/fsck to check the disk for errors."],"exampleFix":"// before\nDownload(url, destDisk); // destDisk has 100MB free, file is 2GB\n// after\nif (GetFreeSpace(destDisk) < expectedSize) {\n    destDisk = PickDriveWithSpace(expectedSize); // avoid DiskError mid-download\n}","handlingStrategy":"validation","validationCode":"var drive = new DriveInfo(Path.GetPathRoot(destPath));\nif (drive.AvailableFreeSpace < expectedSizeBytes)\n    throw new IOException($\"Insufficient space on {drive.Name}\");","typeGuard":null,"tryCatchPattern":"try { Download(url, dest); }\ncatch (DownloadException e) when (e.ErrorCode == ErrorCode.DiskError) {\n    Log.Error(e.InnerException, \"Disk problem - not retrying\");\n    FreeSpaceOrChangeDestination();\n}","preventionTips":["Check free space before starting large downloads","Exclude download dir from AV/backup file locks","Download to local disks, not removable/network volumes","Never retry DiskError automatically - it wastes cycles"],"tags":["disk","io","filesystem"],"backgroundTag":"file-write-failed","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"}