mDNS discovery service leaks 7 goroutines per Node.Stop() (production default has mDNS on)
Report
Severity: Minor (XE tier ceiling 650 XE). CVSS 3.1: 4.0 (AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L) — CVSS Medium at the boundary; XE tier Minor per the bounty tier table (see §7).
Target: github.com/xeprotocol/xe @ 89a542ea51d38375299aee54c6c99102e9bfa666 ("release: testnet-0005 quorum withhold fix", 2026-11-10). Go 1.25.0.
1. Impact (read this first)
With mDNS enabled — the production default — every Node.Stop() leaks 7 goroutines (libp2p mDNS + zeroconf + socket pollers) plus their UDP sockets, for process lifetime. Measured deterministically at HEAD: after Stop + 15 s settle, goroutines 2 → 9 (+7): p2p/discovery/mdns +1, libp2p/zeroconf/v2 +2, internal/poll.runtime_pollWait +4. In-process Stop→Start cycles accumulate +7 per cycle.
The impact is bounded: a single-run production process exits cleanly and the OS reclaims everything, so the leak bites embedders, test harnesses, and repeated in-process restarts. No remote trigger, no funds, no state impact. That bound is why this is Minor.
2. Root cause
xenet.SetupDiscovery (net/host.go:166-171) starts the mDNS service and throws the handle away:
svc := mdns.NewMdnsService(h, mdnsServiceTag, n)
return svc.Start()
No Close() call site for the service exists anywhere in the repo. Node.Stop() (node/node.go:1301-1308) closes the libp2p host, but that does not stop the mDNS service — the service is library-owned, started without retaining a handle, and no shutdown path reaches it.
3. Scenario (how it happens)
- A node runs with mDNS enabled (the production default,
DisableMDNS=false). - The node is stopped (
Node.Stop()), e.g. during a restart, an upgrade, or a test-harness cycle.Stop()closes the host; the mDNS service keeps running. - After Stop + 15 s, 7 goroutines survive: 1 mDNS, 2 zeroconf, 4 socket pollers — plus the UDP sockets they hold. The next in-process Start→Stop cycle adds 7 more. The control (T3-6, mDNS + discovery disabled) returns exactly to baseline after Stop + 15 s on both MemStore and Badger — the leak is mDNS-specific, and the DHT internals the lifecycle map predicted would survive do NOT (they exit on
Host.Close()).
4. Proof of concept (local, deterministic)
PoC: hunt-v3/stage3/tests/ — TestT36b_MDNSEnabled (node/, -race, 15.10 s), re-run byte-identical at HEAD in an isolated worktree copy with temp data dirs. The test only logs LEAK-SIGNAL; the verdict is read from the numbers.
Re-run result at HEAD (2026-11-14), identical to V3 (2026-11-11):
| Observation | V3 | Re-run at HEAD |
|---|---|---|
| Goroutines before → after Stop + 15 s | 2 → 9 (+7) | 2 → 9 (+7) |
| Breakdown | mdns +1, zeroconf +2, pollWait +4 | mdns +1, zeroconf +2, pollWait +4 |
| Stop latency | — | 8.13 ms |
| Control (mDNS off) | baseline | baseline (V3 control) |
| Race detector | 0 DATA RACE |
0 DATA RACE |
Log: hunt-v4-followup/stage3-minors/logs/t36b-reverify.log. The test files were copied byte-identical (cmp clean; sha256 430e05fd525fe5d7188bed468589b4b174661b1f1ef9537ac9b22e529b5b7af8 for node/stage3_lifecycle2_test.go).
5. Attacker prerequisites
- None — local only, no attacker. The trigger is a local
Stop()with mDNS on (the default). No remote step, no privilege on the victim. Accumulation needs repeated in-process Stop→Start cycles.
6. Independent validation and false-positive assessment
- Deterministic reproduction, twice: V3 (2026-11-11) and the HEAD re-run (2026-11-14) give the exact same count and the exact same goroutine breakdown. The survivors are named from
runtime.Stack, not inferred. - Disproof attempted: the lifecycle map predicted DHT internals would also survive — disproved by the T3-6 control (mDNS off returns exactly to baseline); mDNS confirmed by the T3-6b delta. The leak is mDNS-specific.
- Duplicate check (fresh, DB 2,421 entries as of 2026-11-14 ~17:00 WIB): the only mDNS DB hit is xe#434 — an ingress flood (
discoveryNotifeewithout rate-limit: every peer found via mDNS is immediately dialled), a different function (HandlePeerFound) and the opposite direction from this lifecycle defect. All other goroutine-leak reports (xe#330/XE-3444 tunnel proxy loops, XE-5430 SetupCertSync churn, net/sync and gossip ctx reports) name different functions. Open PR #207/#239 (body + files list read) counts outbound peers against inbound sybil discovery suppression innet/discovery.go; it does not touchSetupDiscoveryor any mDNS handle. Classification: NOVEL on public data (private Critical/Severe reports may exist; uniqueness is not guaranteed). Full analysis:duplicate-intel/reports/v4f-t36b-mdns-duplicate-analysis.md.
7. Severity justification (Minor, ceiling 650 XE)
CVSS 3.1: 4.0 (AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L). Attack vector is local (a local Stop); complexity is Low (every Stop with mDNS on leaks); no privileges or user interaction; availability impact is Low (7 goroutines + sockets per Stop, accumulating only across in-process restarts; no crash, no state impact, no funds). The CVSS score sits exactly on the Low/Medium boundary (4.0); the XE tier is Minor because the bounty tier table prices this class — a small bounded lifecycle leak with no remote trigger and no production single-run impact — as Minor, and the CVSS number is informational here.
Why not higher: a single-run production process is unaffected beyond its own exit; the leak needs in-process restarts to accumulate.
8. Fix suggestion
Retain the mDNS service handle from SetupDiscovery (return it alongside the error, or store it on the host/node) and call Close() on it from Node.Stop() (or from Host.Close() if libp2p owns the service lifetime). One retained handle + one close call closes the finding; no other call site needs to change.
9. Caveats (kept in the report)
- Impact is bounded to embedders / test harnesses / repeated in-process restarts; a single-run production process exits cleanly.
- Production default has mDNS on, so the leak occurs on every normal Stop — but only accumulates across in-process cycles.
- NOVEL means no matching public finding as of the 2026-11-14 ~17:00 WIB check (DB 2,421 entries); private reports may exist.
10. Reproduction (for the committee)
Local only, worktree copy at 89a542e, isolated temp data dirs:
export PATH=~/workspace/go/go/bin:$PATH
export TMPDIR=~/workspace/xe-bounty/.tmp
cd <worktree>/node
go test -race -count=1 -timeout 5m -run 'TestT36b_MDNSEnabled$' -v ./...
# Expected: PASS (exit 0) — read the LEAK-SIGNAL numbers from the log:
# goroutines 2 -> 9 after Stop + 15 s (mdns +1, zeroconf +2, pollWait +4).
PoC: hunt-v3/stage3/tests/ (node/stage3_lifecycle2_test.go). Log: hunt-v4-followup/stage3-minors/logs/t36b-reverify.log. Full analysis: hunt-v3/stage3/STAGE3_VERDICT.md §T3-6b; duplicate analysis: duplicate-intel/reports/v4f-t36b-mdns-duplicate-analysis.md.
Thread
Thanks for the report. We have read it against the code and confirmed the behaviour you describe. It is being handled, and this ticket will be updated when there is a change to check.