You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Does iMCP possibly leak an NWBrowser on each discovery timeout, and therefore cause mDNSResponder to run out of file descriptors? #174
// Set up a timeout task to ensure we don't wait forever
lettimeoutTask=Task{
// Allow 30 seconds to find the service
tryawaitTask.sleep(for:.seconds(30))
// If we haven't found a service by now, resume with an error
ifawaitconnectionState.checkAndSetResumed(){awaitlog.error("Bonjour service discovery timed out after 30 seconds")continuation.resume(throwing:MCPError.internalError("Service discovery timeout"))}}
Wouldn't this mean that when NWBrowser doesn't find a service within 30 secs, that instance is never cancelled?
My understanding is that each started NWBrowser keeps a socket open to mDNSResponder. So, basically if you never cancel them, eventually they'll add up and cause mDNSResponder to hit whatever its internal file descriptor limit is.
It sure does. Days of troubleshooting why my DNS keeps getting screwed up machine-wide resulted in this:
Title: imcp-server leaks DNS-SD socket connections, exhausting mDNSResponder and breaking system-wide DNS
Summary
imcp-server steadily leaks unix-domain socket connections to macOS's mDNSResponder (the system DNS/Bonjour daemon) — apparently one per resolution/network operation, never released. Over ~18h of uptime it accumulated ~10,200 open connections, exhausting mDNSResponder's file-descriptor limit (~10,240). Once exhausted, all system DNS resolution fails machine-wide until mDNSResponder is force-restarted.
Environment
iMCP version: (defaults read /Applications/iMCP.app/Contents/Info CFBundleShortVersionString)
macOS Darwin 25.4.0; iMCP running as an MCP server
Impact: High. A single leaking helper silently breaks DNS for the whole machine, recoverable only via sudo killall mDNSResponder. It's hard to diagnose because apps with their own resolver (Chrome's DoH, dig) keep working while everything using the system resolver fails.
Evidence
With DNS dead, mDNSResponder had 10,254 FDs, 10,227 of them unix sockets (DNS-SD client connections). Tracing those to their owner points straight at imcp-server — a near-exact match:
$ sudo lsof -U +c0 | awk 'NR>1{print $1}' | sort | uniq -c | sort -rn | head
10227 mDNSResponder
10224 imcp-server ← peer ends of the leaked connections
236 node
Concurrent: mDNSResponder logging open() failed: Too many open files continuously; dns-sd -G → -65563 (ServiceNotRunning). Leak rate is steady (~9/min) regardless of activity — consistent with a per-operation handle that's created but never deallocated.
Suspected cause: A DNSServiceRef (DNSServiceGetAddrInfo/Browse) or NWConnection/NWBrowser/NWPathMonitor created per operation but never DNSServiceRefDeallocate'd / cancel()ed. Each opens a unix socket to mDNSResponder; not tearing it down leaks one per call.
Confirm: Let it run a few hours and watch the count climb without bound:
sudo lsof -U +c0 | awk '$1=="imcp-server"' | wc -l
Workaround: Restart iMCP to release the sockets, then sudo killall mDNSResponder.
Thx for sharing that @ApptivistsKafe. It looks like @grlee is attempting to fix this bug in grlee#1. I don't feel qualified to review that pr, but hopefully @mattt will take a look at it soon.
Activity
ApptivistsKafe commentedon Jun 26, 2026
It sure does. Days of troubleshooting why my DNS keeps getting screwed up machine-wide resulted in this:
Title: imcp-server leaks DNS-SD socket connections, exhausting mDNSResponder and breaking system-wide DNS
Summary
imcp-server steadily leaks unix-domain socket connections to macOS's mDNSResponder (the system DNS/Bonjour daemon) — apparently one per resolution/network operation, never released. Over ~18h of uptime it accumulated ~10,200 open connections, exhausting mDNSResponder's file-descriptor limit (~10,240). Once exhausted, all system DNS resolution fails machine-wide until mDNSResponder is force-restarted.
Environment
iMCP version: (defaults read /Applications/iMCP.app/Contents/Info CFBundleShortVersionString)
macOS Darwin 25.4.0; iMCP running as an MCP server
Impact: High. A single leaking helper silently breaks DNS for the whole machine, recoverable only via sudo killall mDNSResponder. It's hard to diagnose because apps with their own resolver (Chrome's DoH, dig) keep working while everything using the system resolver fails.
Evidence
With DNS dead, mDNSResponder had 10,254 FDs, 10,227 of them unix sockets (DNS-SD client connections). Tracing those to their owner points straight at imcp-server — a near-exact match:
$ sudo lsof -U +c0 | awk 'NR>1{print $1}' | sort | uniq -c | sort -rn | head
10227 mDNSResponder
10224 imcp-server ← peer ends of the leaked connections
236 node
Concurrent: mDNSResponder logging open() failed: Too many open files continuously; dns-sd -G → -65563 (ServiceNotRunning). Leak rate is steady (~9/min) regardless of activity — consistent with a per-operation handle that's created but never deallocated.
Suspected cause: A DNSServiceRef (DNSServiceGetAddrInfo/Browse) or NWConnection/NWBrowser/NWPathMonitor created per operation but never DNSServiceRefDeallocate'd / cancel()ed. Each opens a unix socket to mDNSResponder; not tearing it down leaks one per call.
Confirm: Let it run a few hours and watch the count climb without bound:
sudo lsof -U +c0 | awk '$1=="imcp-server"' | wc -l
Workaround: Restart iMCP to release the sockets, then sudo killall mDNSResponder.
jerzygangi commentedon Jun 27, 2026
Thx for sharing that @ApptivistsKafe. It looks like @grlee is attempting to fix this bug in grlee#1. I don't feel qualified to review that pr, but hopefully @mattt will take a look at it soon.
Fix CLI dropping connection instead of reconnecting mid-session (#1)
Fix CLI dropping connection instead of reconnecting mid-session (mattt#1
Cancel the Bonjour browser on every discovery exit path (mattt#199)