#8060·caddy

Unix socket listener keeps listening (clients hang) and its file isn't removed after a reload moves off it

Author: ASIXicleCreated Sep 25, 2026Updated Sep 25, 2026

Issue Details

Caddy version: v2.11.4 h1:XKxkMTgNSizEvKG6QHue6cAsFOteU2qA61w2tKkCWi0= (official linux_amd64 release, built with go1.26.3)

What happens

When a config reload moves a listener off a Unix socket (the admin endpoint, or a site's bind unix/...), the old socket keeps listening but nothing accepts on it. A client that connects to the old path hangs instead of getting "connection refused". The log still says stopped previous server for the old admin address.

It only clears at the process's next garbage collection. In an idle process that's the 2-minute forced GC: in 5 runs with GODEBUG=gctrace=1, the old socket stopped listening 124–130 s after the reload, each time at the first GC after the reload. With GOGC=off it never cleared (watched for 150 s). The socket file stays on disk afterwards.

Moving between TCP addresses doesn't do this: the old port refuses immediately.

Reproduce

bash
mkdir -p /tmp/caddy-repro && cd /tmp/caddy-repro
printf '{\n    admin unix//tmp/caddy-repro/admin.sock\n}\n:8081 {\n    respond ok\n}\n' > A
printf '{\n    admin localhost:2999\n}\n:8081 {\n    respond ok\n}\n' > B
caddy run --config A --adapter caddyfile &
sleep 1
caddy reload --config B --adapter caddyfile --address unix//tmp/caddy-repro/admin.sock
curl -sS --max-time 5 --unix-socket /tmp/caddy-repro/admin.sock http://localhost/config/; echo "curl exit $?"
ss -xlp | grep caddy-repro
ls -l /tmp/caddy-repro/admin.sock

Output:

bash
curl: (28) Operation timed out after 5005 milliseconds with 0 bytes received
curl exit 28
u_str LISTEN 1      4096   /tmp/caddy-repro/admin.sock 6499819            * 0    users:(("caddy",pid=58867,fd=9))
s-w------- 1 user user 0 Sep 25 01:29 /tmp/caddy-repro/admin.sock

The result is the same with a |0600 mode suffix on the socket address, when moving from one Unix socket to another, and for a site bind unix/... moved to a TCP port. Moving back to the same path works, but leaves two LISTEN sockets on that path (the orphan and the new one).

Expected

The same as TCP: after the reload the old socket is closed (connect is refused) and its file is removed.

Likely cause (listen_unix.go, (*unixListener).Close)

go
if newCount == 0 {
    file, err := uln.File()
    var name string
    if err == nil {
        name = file.Name()
    }
    defer func() {
        // ...
        if err == nil {
            _ = syscall.Unlink(name)
        }
    }()
}
return uln.UnixListener.Close()
  • uln.File() returns a dup() of the listening fd that is never closed, so the socket keeps listening until the *os.File finalizer runs at the next GC.
  • file.Name() isn't the socket's path. For a file obtained from a net listener, Go names it netFD.name(), which is net + ":" + laddr + "->" + raddr (net/fd_posix.go). So the Unlink targets unix:/tmp/caddy-repro/admin.sock->, fails silently, and leaves the file.

Taking the path from uln.Addr().String() (or the stored listener address) instead of calling File() would fix both.

Impact: low. Nothing is exposed (the old socket never answers), but anything still pointed at the old path (a script, caddy reload --address …, a proxy in front) stalls for up to ~2 minutes instead of failing fast. Possibly relevant to #7516 (Unix admin socket by default) and to the socket-reuse logic from around #5568.

Assistance Disclosure

AI used

If AI was used, describe the extent to which it was used.

Found, reproduced and root-caused by Claude (Anthropic) agents while hardening my own Caddy setup. Claude wrote the repro and this report; I reviewed it before filing.