Repository navigation
Description
imcp-server leaks DNSServiceCreateConnection/DNSServiceBrowse handles, eventually killing all DNS on the machine
Summary
imcp-server opens a new DNSServiceCreateConnection and a DNSServiceBrowse
roughly every 37 seconds and never deallocates either. Each leaked connection holds an
open Unix-domain socket in both imcp-server and mDNSResponder. Given enough time,
mDNSResponder exhausts its descriptor table and begins refusing all new client
connections with EMSGSIZE, at which point every newly launched process on the Mac
fails DNS resolution instantly — not just MCP clients.
This is a machine-wide outage, and it is easy to misattribute: dig/host keep working
(they bypass mDNSResponder), and long-lived processes that already hold an mDNS
connection keep resolving, so the machine looks half-alive. I spent a while blaming
Tailscale and then macOS DDR before finding this.
Environment
- iMCP 1.4.0 (build 10),
co.dododo.iMCP - macOS 26.6.2 (25G83), arm64 (Mac Studio)
- Client: Claude Code, stdio MCP server
Evidence: the leak
Measured from the mDNSResponder unified log over an 80-minute window, 6 imcp-server
processes running:
DNSServiceCreateConnection START : 857
DNSServiceCreateConnection STOP : 70 <-- 787 never closed
DNSServiceBrowse START : 788
DNSServiceBrowse STOP : 2 <-- 786 never stopped
DNSServiceQueryRecord START : 3370
DNSServiceQueryRecord STOP : 3370 <-- other clients are balanced
786 of the 788 browses came from imcp-server. Every other DNS client on the machine
was in single digits. A single process, sampled directly:
DNSServiceCreateConnection START PID[79052](imcp-server) 19:15:37
DNSServiceCreateConnection START PID[79052](imcp-server) 19:16:14
DNSServiceCreateConnection START PID[79052](imcp-server) 19:16:51
DNSServiceCreateConnection START PID[79052](imcp-server) 19:17:28
... (no STOP, ever)
The browse is the WAB/mDNS domain enumeration:
DNSServiceBrowse Start domain enumeration for WAB and mDNS PID[79052](imcp-server)
Evidence: measured rate and ceiling
Controlled reproduction — spawned N bare imcp-server processes and watched
mDNSResponder's descriptor count climb:
- ~1.7 leaked Unix sockets per process per minute, monotonic, never reclaimed.
- Linear over 2.5 hours across 8 → 40 → 150 processes (no plateau, no GC).
- Verified two independent ways — client-side
lsofon theimcp-serverprocesses and
rootlsofonmDNSResponder— which agreed to within 0.08%, confirming each leaked
connection pins a descriptor on both ends. mDNSResponderwedged at ~12,540 open descriptors (mdns_fds=12558,
mdns_unix=12529).
At a realistic 6-8 leaking processes that is roughly 16 hours to total DNS failure.
Symptoms at the ceiling
dscacheutil -q host -a name example.com -> EMPTY
getaddrinfo("example.com") -> EAI_NONAME, instantly, no wire query
dig @8.8.8.8 example.com -> works (bypasses mDNSResponder)
dig example.com -> works
mDNSResponder log -> ERROR: read_msg errno 40 (Message too long)
errno 40 is EMSGSIZE. On a Unix socket, recvmsg returns this when the receiver
cannot allocate descriptors for the SCM_RIGHTS rights being passed — i.e.
mDNSResponder is out of descriptors and can no longer accept client connections.
Recovery is immediate and does not require restarting mDNSResponder:
kill $(pgrep -x imcp-server) -> DNS answering within 1 second
Reproduction
for i in $(seq 1 40); do
nohup /Applications/iMCP.app/Contents/MacOS/imcp-server < /dev/zero >/dev/null 2>&1 &
done
# watch it climb (no root needed):
while true; do
echo "$(date +%T) $(for p in $(pgrep -x imcp-server); do lsof -p $p; done | grep -c unix)"
sleep 30
done
# recover:
kill $(pgrep -x imcp-server)Compounding bug: orphaned processes
imcp-server detaches to ppid=1 and outlives the MCP client session that spawned
it. One orphan is left behind per exited client session; 33 had accumulated here over
about two weeks. Since the leak rate is per-process, accumulating orphans steadily
shorten the time to a machine-wide DNS outage. Orphans are indistinguishable from live
servers by parentage (both ppid=1).
Suggested fix
Deallocate the DNSService refs when the browse completes or the server shuts down —
DNSServiceRefDeallocate() on both the browse ref and the connection ref — and reuse a
single long-lived connection rather than creating one per enumeration. Separately,
imcp-server should exit when its stdio client disconnects.
Happy to supply raw logs, the full descriptor-climb series, or to test a patch.
Activity
Cancel the Bonjour browser on every discovery exit path (#199)