<!-- XE-12833 · mDNS discovery service leaks ~8 goroutines per Node.Stop(); the MdnsService handle is discarded and never closed · testnet -->
*Markdown view of <https://bounty.xe.network/XE-12833>. The page is the record; this is the same page for reading.*

XE-12833 · Bounty

# mDNS discovery service leaks \~8 goroutines per Node.Stop(); the MdnsService handle is discarded and never closed

Closed · duplicate
—claimed Minor
web
filed 2026-11-14 13:00 UTC
by xe:952f5eaf

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Minor

Area
:   P2P / sync

Duplicate of
:   [XE-13397](https://bounty.xe.network/XE-13397) triaging

Tracked
:   —

Updated
:   2026-11-20 19:45 UTC

Told
:   2026-11-20 19:45 UTC

### Patches

None linked.

### History

- [626334](https://bounty.xe.network/log/626334) 2026-11-20 19:45 UTC proposal.adopted
- [626333](https://bounty.xe.network/log/626333) 2026-11-20 19:45 UTC reply.sent
- [626332](https://bounty.xe.network/log/626332) 2026-11-20 19:45 UTC ticket.status new → closed
- [622471](https://bounty.xe.network/log/622471) 2026-11-20 19:45 UTC proposal.adopted
- [622468](https://bounty.xe.network/log/622468) 2026-11-20 19:45 UTC proposal.adopted
- [622467](https://bounty.xe.network/log/622467) 2026-11-20 19:45 UTC ticket.facts
- [622464](https://bounty.xe.network/log/622464) 2026-11-20 19:45 UTC proposal.adopted
- [622463](https://bounty.xe.network/log/622463) 2026-11-20 19:45 UTC ticket.facts
- [608845](https://bounty.xe.network/log/608845) 2026-11-20 15:02 UTC note.added
- [608844](https://bounty.xe.network/log/608844) 2026-11-20 15:02 UTC proposal.created
- [608843](https://bounty.xe.network/log/608843) 2026-11-20 15:02 UTC proposal.created
- [608842](https://bounty.xe.network/log/608842) 2026-11-20 15:02 UTC proposal.created

[Full history](https://bounty.xe.network/log?ref=XE-12833) · [JSON](https://bounty.xe.network/v1/tickets/XE-12833) · [markdown](https://bounty.xe.network/XE-12833.md)

### Report

# \[Minor\] mDNS discovery service leaks \~8 goroutines per Node.Stop(); the MdnsService handle is discarded and never closed

**Area:** p2p-sync / discovery
**Repo pin:** `xeprotocol/xe` @ `89a542e` (HEAD, verified 2026-11-14)
**Suggested tier:** Minor (CVSS 4.0 — local only, no remote trigger; embedders / test harnesses / repeated in-process restarts only; a single-run production process exits cleanly)
**Related public issue:** `xeprotocol/xe#559` (same ground, filed by another researcher; this report is an independent reproduction with our own Go test and our own measurements)

## Summary

Every `Node.Stop()` with mDNS enabled (the production default) leaks \~8 goroutines. `SetupDiscovery` starts the libp2p mDNS service and throws the handle away, so nothing ever calls `Close()` on it — and `Host.Close()` in `Stop()` does not stop it either, because the service owns its own multicast socket, not the swarm. The leaked goroutines (zeroconf browse/server loops) run forever, so an embedder or test harness that restarts nodes in-process accumulates 8 goroutines per restart with no way to reclaim them.

## Root cause

- `net/host.go:166-171` — `SetupDiscovery` creates the service in a local and returns only the `Start()` error:

  ```
  svc := mdns.NewMdnsService(h, mdnsServiceTag, n)
  return svc.Start()
  ```

  The handle is discarded at the call site (`node/node.go:207`); `MdnsService` has exactly **one** mention in non-test code in the whole repo, and **no `Close()` call site exists anywhere**.
- `node/node.go:1301-1308` — `Stop()` cancels the context, waits on the WaitGroup, closes the vote manager, the host and the store — but never touches the mDNS service, and the service's goroutines do not observe the node context or the host lifecycle.

## Reproduction (our own Go test, `node/zz_r56_m2_mdns_b56_test.go`)

Three full `New()` \+ `Stop()` cycles with mDNS on (production default) and fresh data dirs. Measured at HEAD, 2026-11-14 (two runs, identical counts):

| Cycle | Goroutines after `Stop()` | Delta vs baseline |
| --- | --- | --- |
| baseline | 2 | — |
| 1 | 10 | \+8 |
| 2 | 18 | \+16 |
| 3 | 26 | **\+24 (\+8.0/cycle, monotonic)** |

Attribution from the full goroutine dump after cycle 3 (26 goroutines: 2 test harness \+ 24 leaked): **all 24 leaked stacks belong to the mDNS service tree** — 18 pure `libp2p/zeroconf` stacks, 3 pure `discovery/mdns` stacks, 3 stacks spanning both. Representative leaked stack: `zeroconf.(*client).periodicQuery` ← `(*client).run` ← `zeroconf.Browse` ← `mdnsService.startResolver`. No other package accounts for any of the leaked goroutines — the growth is exactly the undisposed mDNS service, 8 goroutines per `Stop()`.

## Impact / worst case

- **Honestly bounded:** a single-run production `xe node` exits cleanly and the OS reclaims the goroutines. The impact is on embedders and test harnesses that create and stop nodes repeatedly in one process: 8 immortal goroutines per restart (plus the multicast sockets they hold), growing without bound across restarts, with no API to stop them.
- No remote trigger, no crash, no state corruption, no funds: a lifecycle leak on the shutdown path. Hence Minor.

## Duplicate check (re-verified at filing time, 2026-11-14 \~12:52–13:0x UTC)

- Board search `q=mDNS` → 15 hits, none a lifecycle/`Stop()` leak. Closest are XE-7925 (new Medium — `--no-discovery` does not isolate a node, DHT bootstrap dials unconfigured public peers; a flag-semantics/isolation defect, read in full) and XE-3098 (new Minor — docs say there is no ambient peer discovery). The other 13 are sync, CLI, docs, or SSH tickets that merely mention discovery.
- `q=zeroconf` → **0 hits**. `q=SetupDiscovery` → **0 hits**. A corpus title scan for mDNS/zeroconf titles finds no lifecycle-leak ticket.
- `q=aurorabelle788` → 1 hit, XE-12805 (our own earlier filing) — the #559 author has not filed on the board. No new public filings since XE-12805 (XE-12806–XE-12825 all 404); xe HEAD still `89a542e`, pull-refs still 186, max PR #556 — no fix PR.

## Remediation suggestion

Keep the `MdnsService` handle (return it from `SetupDiscovery` or store it on the `Node`) and call `Close()` on it in `Node.Stop()` before closing the host. Alternatively, tie the service's lifetime to the node context so `cancel()` in `Stop()` retires its goroutines.

### Thread

**Joseph Denne**team2026-11-20 19:45 UTCdesk

Thanks. This is the same finding as https://bounty.xe.network/XE-13397, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, file a new report that links https://bounty.xe.network/XE-12833 and says what differs; it is read like any other.
