Skip to content

URLSession temp files leaked on every download (CFNetworkDownload_*.tmp) #52

Description

@es617

Every successful file download via HubClient.downloadFile() leaks the CFNetworkDownload_*.tmp file in the system temp directory. These accumulate silently — in my testing, 50 GB of temp files built up over one day of normal usage.

Root cause: In HubClient+Files.swift, after URLSession.download(for:delegate:) returns a tempURL, it's copied into the blob cache via HubCache.storeFile() which uses copyItem, not moveItem. The original tempURL is never deleted. This happens on the success path, not just errors/cancellation.

Two locations:

  • ETag-aware cache flow (~line 698)
  • Generic non-ETag fallback (~line 787)

Reproduction: # After a few model downloads via HubApi().snapshot(): du -ch $TMPDIR/CFNetworkDownload_*.tmp | tail -1 # 50G total

Fix: Two lines — try? FileManager.default.removeItem(at: tempURL) after storeFile() in both locations.

Note: #21 fixes this by rewriting the download path to use moveItem(at: tempURL, to: blobPath) instead of copy-to-cache. That PR also eliminates the duplicate downloadBase copy by using symlinks, halving disk usage per model. It's been open since December 2025.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions