subhra74/xdm · error · DownloadException
Generic
Generic
Error message
Unexpected EOF :: {piece.Id} What it means
In PieceGrabber.CopyWithFixedLength, the read loop expects a known number of bytes; if sourceStream.Read returns 0 before 'remaining' reaches zero, the network stream ended prematurely. The grabber throws DownloadException with ErrorCode.Generic and the piece id, indicating a truncated transfer.
Solutions
- Retry the download - the outer PieceGrabber loop will reconnect and request the remaining range.
- Increase retry count/delay (Config.Instance.MaxRetry, RetryDelay) for unstable networks.
- Use a wired/stable connection or disable power-management on the network adapter for long transfers.
- Verify the server serves the full range reliably; test with curl -r and compare byte counts.
Example fix
// before
var x = sourceStream.Read(BUF, 0, (int)Math.Min(BUF.Length, remaining));
if (x == 0) throw new DownloadException(ErrorCode.Generic, "Unexpected EOF :: " + piece.Id);
// after
var x = sourceStream.Read(BUF, 0, (int)Math.Min(BUF.Length, remaining));
if (x == 0) {
if (remaining > 0 && retryCount++ < maxReconnects) { ReconnectAndContinue(); return; }
throw new DownloadException(ErrorCode.Generic, "Unexpected EOF :: " + piece.Id);
} Defensive patterns
Strategy: retry
Validate before calling
// prefer servers/proxies with reliable keep-alive; before long downloads if (!NetworkInterface.GetIsNetworkAvailable()) await WaitForNetworkAsync();
Try / catch
try { Download(); }
catch (DownloadException e) when (e.Message.StartsWith("Unexpected EOF")) {
await Task.Delay(backoff);
ResumeFromLastGoodOffset();
} Prevention
- Use stable connections for large downloads
- Increase retry count/delay for flaky networks
- Avoid proxies that time out long idle reads
- Keep pieces small so EOF loses less work
When it happens
Trigger: The HTTP response body ends before the expected piece length: server closes connection early, connection dropped mid-transfer, or Content-Length promised more bytes than actually sent.
Common situations: Unstable Wi-Fi/mobile connections dropping mid-transfer, aggressive server/proxy idle timeouts killing long reads, CDN edge disconnects, VPN interruptions during large downloads.
Related errors
AI-assisted analysis of subhra74/xdm@1ca5a25aae (2026-09-13).
Data as JSON: /api/errors/db3cda57eec7d8e6.
Report an issue: GitHub.
Appendix: source
Thrown at app/XDM/XDM.Core/Downloader/Progressive/PieceGrabber.cs:289
if (remaining <= 0)
{
if (maxByteRange > 0 && this.callback.ContinueAdjacentPiece(this.pieceId, maxByteRange))
{
piece = this.callback.GetPiece(this.pieceId);
remaining = piece.Length - piece.Downloaded;
}
else
{
CloseUnfinishedRequest(count);
break;
}
}
var x = sourceStream.Read(BUF, 0,
(int)Math.Min(BUF.Length, remaining));
this.CancellationToken.ThrowIfCancellationRequested();
if (x == 0)
{
throw new DownloadException(ErrorCode.Generic, "Unexpected EOF :: " + piece.Id);
}
try
{
targetStream.Write(BUF, 0, x);
count += x;
}
catch (IOException ioe)
{
Log.Debug(ioe, "Disk error");
throw new NonRetriableException(ErrorCode.DiskError, "Disk error :: " + piece.Id, ioe);
}
if (this.CancellationToken.IsCancellationRequested) return;
this.callback?.UpdateDownloadedBytesCount(this.pieceId, x);
this.callback?.ThrottleIfNeeded();
}
}
finally
{
View on GitHub (pinned to 1ca5a25aae)