LykosAI/StabilityMatrix · error · ApplicationException
Not enough free space to download file. Free
Error message
Not enough free space to download file. Free: {freeSpace} bytes, Required: {contentLength} bytes What it means
DownloadToFileAsync checks the Content-Length of the response against the free disk space on the drive that will hold downloadPath. If free space is less than the required content length, it throws ApplicationException before writing anything. It is a pre-flight guard so large downloads fail fast instead of mid-stream with an out-of-space IO error.
Solutions
- Free disk space on the drive containing downloadPath (delete old packages/models) and retry
- Choose a downloadPath on a drive with enough free space (query DriveInfo to pick one)
- Catch ApplicationException, surface the free/required byte counts to the user, and let them pick another location
- Check contentLength in advance for URLs you control and warn before starting the download
Example fix
// before
await downloadService.DownloadToFileAsync(url, downloadPath);
// after
var drive = new DriveInfo(Path.GetPathRoot(Path.GetFullPath(downloadPath))!);
if (drive.AvailableFreeSpace < requiredBytes)
throw new InvalidOperationException($"Need {requiredBytes} bytes, only {drive.AvailableFreeSpace} free on {drive.Name}");
await downloadService.DownloadToFileAsync(url, downloadPath); Defensive patterns
Strategy: validation
Validate before calling
var dir = Path.GetDirectoryName(Path.GetFullPath(downloadPath));
var freeSpace = SystemInfo.GetDiskFreeSpaceBytes(dir);
// contentLength from a HEAD request:
using var head = await client.SendAsync(new HttpRequestMessage(HttpMethod.Head, url));
var required = head.Content.Headers.ContentLength ?? 0;
if (freeSpace.HasValue && freeSpace.Value < required)
throw new InvalidOperationException($"Need {required} bytes, only {freeSpace.Value} free on {dir}"); Try / catch
try
{
await downloadService.DownloadToFileAsync(url, path);
}
catch (ApplicationException ex) when (ex.Message.StartsWith("Not enough free space"))
{
logger.LogWarning(ex, "Insufficient disk space for {Path}", path);
PromptUserForAnotherDrive();
} Prevention
- Check DriveInfo.AvailableFreeSpace (plus headroom for extraction) before large downloads
- Place downloadPath on the drive with the most free space
- Surface free/required byte counts in the UI before starting
- Watch for disk filling during other concurrent operations (caches, temp files)
When it happens
Trigger: Calling DownloadToFileAsync for a file whose Content-Length exceeds free space on the target drive. Only triggered when Content-Length > 0 (known-size downloads); chunked/indeterminate downloads skip the check and may fail later with IOException.
Common situations: Downloading multi-GB model checkpoints to a nearly-full drive (often C: on Windows); downloadPath on a small system drive or a full RAM disk/network share; downloadUrl pointing at a huge file by mistake.
Related errors
- File ( ) was not found
- Length cannot be null when latentType is Hunyuan
- Python download hash mismatch: expected , actual
- Invalid Token
- Model file name must contain a valid file name.
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/4e31f97e8b099c9b.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Core/Services/DownloadService.cs:86
break;
logger.LogDebug("Retrying get-headers for content-length");
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
response = await client
.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
.ConfigureAwait(false);
contentLength = response.Content.Headers.ContentLength ?? 0;
}
var isIndeterminate = contentLength == 0;
if (contentLength > 0)
{
// check free space
if (
SystemInfo.GetDiskFreeSpaceBytes(Path.GetDirectoryName(downloadPath)) is { } freeSpace
&& freeSpace < contentLength
)
{
throw new ApplicationException(
$"Not enough free space to download file. Free: {freeSpace} bytes, Required: {contentLength} bytes"
);
}
}
await using var stream = await response
.Content.ReadAsStreamAsync(cancellationToken)
.ConfigureAwait(false);
var stopwatch = Stopwatch.StartNew();
var totalBytesRead = 0L;
var buffer = new byte[BufferSize];
while (true)
{
var bytesRead = await stream.ReadAsync(buffer, cancellationToken).ConfigureAwait(false);
if (bytesRead == 0)
break;
await file.WriteAsync(buffer.AsMemory(0, bytesRead), cancellationToken).ConfigureAwait(false);
View on GitHub (pinned to af93d6ef57)