Skip to content

fix(mdns): stop advertising the computer's hostname over mDNS - #235

Open
stevbev wants to merge 3 commits into
NVIDIA:developfrom
stevbev:fix/mdns-hostname-claim
Open

stevbev wants to merge 3 commits into
NVIDIA:developfrom
stevbev:fix/mdns-hostname-claim

Conversation

@stevbev

@stevbev stevbev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes #229

On macOS, PAIR's discovery advertisement turned the computer's Local hostname into <name>-2.

PAIR's node scanner advertises the node as one _nvpair-node._tcp record. Its SRV target and A records named the machine's own hostname — so PAIR became a second mDNS responder asserting a name the operating system's own responder already owned. RFC 6762 treats two responders disagreeing over a unique record as a conflict, and macOS resolves it the way Bonjour does: it renames the computer's Local hostname, appending -2. Every PAIR start re-litigated the name; nothing the user configures prevents it.

The fix is one rule: PAIR now advertises a host record it owns and nobody else can claim.

  • The SRV target and A records carry a synthetic label derived from the node's stable UUID — nvpair-<first twelve hex digits> (example: nvpair-9d4e7c1a06b3). It is stable across restarts and link changes, and already tied to the node identity because the same UUID is in the record's TXT.

  • The service instance name is still the computer's hostname, unchanged: node names in the UI and in every consumer's directory entries behave exactly as before. Hostnames remain display-only.

  • On shutdown the scanner retracts every record it claimed (PTR, SRV, TXT, A at TTL 0), so peers drop the node immediately instead of waiting out cached entries. The wait for that retraction now runs whichever way the browse loop ends: daemon.run kept its bounded join inside the ctx.Done() branch of its select, but cancellation makes that case and the browser's closed events channel ready at the same instant and select takes either, so about half of cancellations returned with responder.Run still inside its shutdown — see the follow-up below.

  • The record ID consumers use to track a discovery record no longer hashes that SRV target host label. The SRV target is not connection information and no consumer reads it, so dropping it means upgrading a node neither re-keys its discovery record nor disturbs pairing or cluster state.

  • If no usable node identity is available, the label falls back to a hash of the hostname (still never the hostname itself), with a warning that the name follows renames; with no entropy at all, the scanner advertises nothing rather than a placeholder everyone would collide on.

No macOS configuration is involved, required, or recommended anywhere in this change — the defect was PAIR claiming a name it did not own, and the fix is PAIR stopping.

Follow-up on review: the shutdown join now runs on every way out of the browse loop

daemon.run started the mDNS responder, then waited for it only in the case <-ctx.Done() branch of its select over ctx.Done() and the browser's events channel. discovery.Browser.Run closes that channel as it stops on ctx.Done(), so on cancellation both cases are ready at once and Go picks one at random: when it picked the closed channel, run returned without ever waiting, and the process could exit with the goodbye still in progress (reproduced on DGX Spark and macOS).

The cleanup — the bounded waitForShutdown on the responder, plus the CloseIdle calls that belonged with it — now sits in a single defer registered before the loops start, so both exits wait. daemon's two mDNS collaborators are declared as small interfaces (mdnsResponder, discoveryBrowser) purely so a test can control when each finishes; production wiring is unchanged because mdns.Responder and *discovery.Browser already satisfy them. Two daemon_test.go cases drive one branch each against a responder whose shutdown the test releases, which is the only way to observe the join: the real responder sends its goodbye in microseconds, so no timing assertion against it can distinguish a waited shutdown from a skipped one. The context-cancellation case passed before this change (that branch already waited); the closed-channel case failed with "daemon.run returned while the responder was still sending its goodbye" and passes now.

User-visible behavior is unchanged from the description above; this commit makes the retraction guarantee hold every time instead of about half the time.

Release intent

Changelog title

PAIR no longer claims the computer's hostname on the local network

Changelog body

  • The node scanner advertises a synthetic host record name derived from the node's identity instead of the computer's hostname, so running PAIR no longer makes macOS rename the computer's Local hostname (the <name>-2 suffix).

  • Node records are now fully retracted on shutdown, so peer lists update immediately instead of after cached entries expire.

  • Node names shown in the application are unchanged.

Bumps

  • services: minor
  • nvpair-cluster-manager: none
  • nvpair-engine-manager: none
  • nvpair-errors: none
  • nvpair-job-scheduler: none
  • nvpair-manual-nodes: none
  • nvpair-node-info: none
  • nvpair-node-scanner: minor
  • nvpair-node-settings: none
  • nvpair-proxy: none
  • nvpair-tui: none
  • nvpair-ui-broker: minor
  • nvpair-workload-manager: none

Scope

Included:

  • nvpair-shared/noderec: HostLabel(nodeUUID, hostname) — the one place the label rule lives (UUID → hostname-hash → refuse).

  • nvpair-node-scanner: responder advertises the synthetic label (A records + SRV target); full PTR+SRV+TXT+A TTL-0 goodbye on shutdown; discoveryRecordId no longer hashes the SRV host label; the cross-process test stubs advertise synthetic hosts too, so the test suite can no longer reproduce the collision in CI.

  • nvpair-node-scanner (review follow-up): daemon.run's responder join and idle-peer-client cleanup moved into a single deferred cleanup, so it runs on both exits from the browse loop, plus daemon_test.go cases proving each exit waits (TestDaemonRun_DoesNotReturnBeforeTheResponderHasShutDownWhenTheContextIsCancelled and …WhenTheBrowserClosesItsEvents). mdnsResponder and discoveryBrowser exist only as test seams.

  • Docs: the scanner spec, cluster-manager spec, architecture.mdx, and the noderec comments describe the record as it is now advertised. No specification change was needed for the follow-up: the spec already required the retraction, and the follow-up is what makes daemon.run honor it in all cases.

Excluded deliberately:

  • No RFC 6762 §8 name-probing. Probing would let PAIR keep claiming the machine's name "politely"; the correct fix is not claiming it. One synthetic name, one code path.

  • No compatibility branch for the old record shape. One canonical layout; mixed-version operation was verified, not bridged.

  • The TXT records of test stubs still carry routable addresses (pre-existing; tracked separately).

  • Scanner-side label refresh on hostname rename mid-run (the UUID-derived label does not move on renames; the fallback-hash label does, with a warning) — follow-up candidate.

  • No unbounded wait for the responder. The join is still capped at shutdownJoinTimeout (2s) and logs a warning if it expires: a stalled interface should not hang the broker's wait forever, and the records expire at their TTL anyway.

Validation

Recorded on macOS (Apple Silicon); live 5353 captures on one IPv4 interface; every count below re-derived independently from the raw capture files, not from grep summaries; example hostnames and addresses are pseudonymized.

Wire evidence, recorded on the tree before the review follow-up (de6ce32 / 723e5bb) and not re-derived since:

  • Wire before (old binary, standalone scanner): 260 A + 260 SRV records at TTL 120 naming the machine hostname, teardown = PTR only at TTL 0, zero hostname records ever retracted — the defect, captured.
  • Wire after (this build, two windows): zero PAIR-TTL records naming the hostname; 246 A + 246 SRV at TTL 120 for nvpair-9d4e7c1a06b3.local. (instance name still the hostname; +1 each at TTL 0 in the goodbye).
  • dns-sd -Q nvpair-9d4e7c1a06b3.local A → Addr IN 10.108.6.189. The dns-sd -B/-L browse pair is reported as inconclusive on the test host on purpose: a control (dns-sd -P native registration) proved same-host dns-sd enumeration blind there today even to the system's own stack, so the authoritative channel is raw 5353 capture plus -Q.
  • Goodbye: after SIGTERM, one packet with TTL-0 PTR+SRV+TXT+A sent 45 ms later, before process exit; independently reproduced in the mixed-version capture (second responder, ~0.9 s). Note that these goodbyes were captured on a run that happened to wait; before the follow-up commit the wait was taken only when select chose the ctx.Done() branch, so the "retraction before exit" outcome was not guaranteed by any capture on the old tree.
  • Mixed-version coexistence (old develop-tip scanner + this scanner running concurrently, same network): the wire carries 181 hostname-targeted SRV answers from the old binary and 0 from the new one in the same capture; TXT census attributes both identities cleanly; zero §9 conflict events logged by either responder across the window; both tears down with their own (PTR-only vs full) goodbys.

Re-run on the current tree, including the review follow-up:

  • All Go modules go test ./... from services/: everything passes except nvpair-engine-manager → TestUninstall_TerminatesRunningInstance (one failure, not two; it reproduces at clean develop tip, where the executor refuses to stop a process it treats as externally managed).
  • services/nvpair-node-scanner: 152 tests pass, 0 fail, 1 skip — TestDispatchHardwarePreviews_LimitsConcurrentReadsAcrossNodesAndAddresses, which needs a second loopback alias (sudo ifconfig lo0 alias 127.0.0.2) that a default macOS host does not have. The two new daemon_test.go cases are among the passes.
  • cd services/tests && go test ./... -count=1: 94 pass, 0 fail, 6 skip, run beside the installed PAIR, which was live throughout; the six skips are the default-port tests that skip when the installation already holds the port. The earlier figure — 99 pass / 0 fail / 0 skip — was recorded with the installation off and predates the follow-up.
  • services/nvpair-engine-manager: 16 skips besides the failing test, all environment-gated (no vLLM/venv install, no second loopback alias). The earlier "zero skips" claim did not hold on this host and has been replaced with the actual counts.
  • make check and the desktop gates (dead-code:check, service-contracts:check, lint, typecheck, test:unit) exit 0 on the squashed tree as previously recorded; the follow-up commit changes only services/nvpair-node-scanner sources, so no TypeScript, contract, or documentation input changed and those results carry over unchanged.

Risk

  • A node's mDNS target name changes shape on upgrade. Consumers take ports from TXT and treat the instance name as display-only, and the record ID deliberately does not include the host label, so consumers key on unchanged information; mixed-version operation verified above.

  • The fallback label (hostname hash) moves if the hostname changes while no node identity is available. That rung exists only for configurations that cannot persist an identity; the warning is logged next to the advertised name.

  • Advertise-nothing with no entropy is a behavior change: such a configuration advertised a colliding placeholder before and advertises nothing now. That state means no usable node identity and no hostname; advertising anything would recreate this bug.

  • Peers running the old scanner keep advertising hostname-derived names until they upgrade. Coexistence was verified; the contention each old node causes on its own machine is that machine's upgrade to make.

  • daemon's two mDNS collaborators are now interfaces. mdnsResponder and discoveryBrowser exist so a test can control when the responder and the browser finish their shutdown; they add no runtime branch and no second code path, and newDaemon still wires the concrete mdns.Responder and discovery.Browser.

Checklist

  • I have read the Contributing Guidelines.
  • Every commit is signed off (git commit -s), certifying the Developer Certificate of Origin.
  • New or existing tests cover the change.
  • Relevant documentation is updated.
  • I checked the diff, changed filenames, and commit messages for credentials, private data, internal URLs, internal issue identifiers, and generated artifacts.
  • I recorded the validation commands and results above.
  • I declared version bumps in the release-intent block above. services/versions.json is written by automation — do not edit it by hand.

@stevbev
stevbev force-pushed the fix/mdns-hostname-claim branch from b9c3e7b to b1ae820 Compare November 24, 2026 17:05

@Noah-Tervalon-Nvidia Noah-Tervalon-Nvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna go bug someone else for a review just to double check since this is large, but I only found the one issue.

PAIR published A records and an SRV target naming the machine's own hostname,
which made it a second responder asserting the operating system's host name.
macOS responds to that contention by renaming the computer's Local hostname
to <name>-2. PAIR now advertises a synthetic host label derived from the node
UUID, retracts every record it claimed on shutdown, and no longer hashes that
label into discovery record IDs, so existing nodes neither re-key nor re-pair.

Closes NVIDIA#229

Signed-off-by: Steven Beverly <thestevbev@gmail.com>
…e suite

grandcat v1.0.0 sets no write deadline anywhere, and Server.Shutdown holds
its shutdown lock while unregister sends the goodbye on every interface
listMulticastInterfaces reports — loopback, VPN tunnels and peer-to-peer
interfaces included — before it closes any socket. An interface that answers
"network is unreachable" is harmless, because grandcat discards write errors,
but one that accepts the packet into a queue that never drains leaves that
write waiting to become writable indefinitely. Reported on an M5 mac, whose
goroutine dump shows exactly that park.

Route all three grandcat teardowns in the package through one bounded wait:
the cleanup registerTestAdvertisement registers on behalf of every call site,
the control of the hostname-claim guard, and the multicast control of the
discovery diagnosis. The cleanup is the one that matters most — cleanups run
one test at a time, so a parked one stalls every later test until go test's
own timeout dumps the binary.

A teardown that outlives the deadline is reported rather than failed: one
interface that will not take a goodbye should not turn red every test that
advertised anything. That report goes to the test's own *testing.T, because
a throwaway one discards everything written to it.

The bound frees the test, not the write: grandcat's sockets are unexported
and closed only after the write returns, so a stalled advertisement is
retracted when its records reach their TTL. Those records are always a
synthetic label pointing at 127.0.0.1, so the residue is a dead entry a peer
drops by itself, not a live node's entry being replaced.

Test-only: no service binary's compiled output changes.
Signed-off-by: Steven Beverly <thestevbev@gmail.com>
@stevbev
stevbev force-pushed the fix/mdns-hostname-claim branch from b1ae820 to 723e5bb Compare November 25, 2026 21:26
Comment thread services/nvpair-node-scanner/daemon.go Resolved
daemon.run kept the bounded wait for responder.Run inside its ctx.Done()
branch, but cancelling the context makes that case and the browser's closed
events channel ready at the same instant, and select takes either. When it
took the closed channel, run returned with responder.Run still inside its
shutdown, so Scanner.Run could reach process exit with the RFC 6762 §10.1
retraction unsent — the same early return reproduced on DGX Spark and macOS.

Move the responder join, together with the idle peer clients that are closed
alongside it, into one deferred cleanup registered before the loops start, so
both exits wait. The responder is still the only component joined: the other
background loops hold nothing the wire needs after cancellation.

daemon now names its two mDNS collaborators as interfaces so a test can
control when each finishes; production wiring is unchanged, since
mdns.Responder and *discovery.Browser already satisfy them. Without that
seam nothing could prove the wait: the real responder sends its goodbye in
microseconds, so a timing assertion against it cannot tell a joined shutdown
from a skipped one. Two daemon_test cases drive each branch with a responder
whose shutdown the test releases — the closed-channel case failed before this
change, the cancellation case passed because that branch already waited.

Changes nvpair-node-scanner's compiled output: shutdown now waits for the
responder even when the browse loop ends on the browser's closed channel.

Signed-off-by: Steven Beverly <thestevbev@gmail.com>

@nvrithik nvrithik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Thanks for addressing the shutdown-wait concern. The deferred cleanup now covers both context cancellation and browser-channel closure, with regression tests for each path.

Verified both new regression tests with 50 race-detector repetitions each, plus the full scanner race-detector suite; all passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mDNS responder claims the machine's own hostname, so macOS renames its Local hostname to <name>-2

3 participants