Skip to content

fix: never list live sockets or their runtime directories as reclaimable - #71

Open
iyashjayesh wants to merge 1 commit into
guhcostan:mainfrom
iyashjayesh:fix/skip-live-sockets-in-temp-scan
Open

fix: never list live sockets or their runtime directories as reclaimable#71
iyashjayesh wants to merge 1 commit into
guhcostan:mainfrom
iyashjayesh:fix/skip-live-sockets-in-temp-scan

Conversation

@iyashjayesh

Copy link
Copy Markdown

What does this PR do?

Stops the cleaner from deleting the unix sockets of running processes.

$TMPDIR on macOS (/var/folders/*/*/T) is not just scratch files — it is where running processes keep their runtime sockets. getDirectoryItems listed those directories as ordinary reclaimable items, so the temp-files category deleted them and broke whatever owned them.

I hit this with podman. A single clean run wiped $TMPDIR/podman/, which killed gvproxy and the API socket that /var/run/docker.sock symlinks to. The VM process stayed alive, so podman machine list still reported "Currently running" while every connection was refused — a confusing state to debug. Podman Desktop separately reported "Docker socket is not disguised correctly", same cause. Recovery needed podman machine stop && podman machine start.

The failure is visible in the tool's own output, because docker is cleaned after temp-files:

Temporary Files    ✓ 2.9 GB freed
Docker             ✗ Docker cleanup failed: Cannot connect to Podman ...
                     dial tcp 127.0.0.1:56212: connect: connection refused

The scan phase saw a healthy podman and found 13.57 GB reclaimable; by the clean phase, temp-files had deleted the socket the docker step needed. So this also fixes the docker category silently failing on podman setups.

The fix skips sockets and FIFOs, and skips directories containing one (searched two levels deep — runtime directories keep sockets at or near the top). Sockets are 0 bytes, so no reclaimable space is given up.

Type of change

  • Bug fix
  • New feature (new scanner, command, or option)
  • Improvement to existing feature
  • Chore / dependency update
  • Documentation

Related issue

None — found while running the tool.

Checklist

  • bun run lint passes
  • bun run test passes (no regressions)
  • bun run build succeeds
  • New tests added for new behavior
  • I've tested this on macOS locally

Notes for reviewer

The guard lives in getDirectoryItems, so it also covers the trash, system-cache, system-logs, dev-cache, ios-backups and mail-attachments scanners plus the interactive explorer. That is intentional — a live socket is never reclaimable space in any of those locations — but it is a wider blast radius than temp-files alone, so worth a look.

Four tests added: a bare socket, a socket-holding directory, a nested socket, and a plain directory that must still be collected (guarding against over-exclusion).

Verified against a real $TMPDIR (193 entries): 182 still listed, 11 live runtime directories now skipped, podman no longer among them.

macOS 15 (Darwin 25.5.0), arm64, bun 1.x, podman 5.6.2.

$TMPDIR (/var/folders/*/*/T) holds the runtime sockets of running
processes. getDirectoryItems listed those directories as ordinary
reclaimable items, so cleaning temp-files deleted them and broke the
owning process.

For podman this wiped $TMPDIR/podman, killing gvproxy and the API socket
that /var/run/docker.sock points to. The docker category then failed in
the same run with "Cannot connect to Podman", because the temp-files step
had already deleted the socket it needed.

Skip sockets and FIFOs, and skip directories that hold one. Sockets carry
no reclaimable space, so no space is given up by leaving them alone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant