Skip to content

fix: stop the hostname rename loop caused by our own answers (#545) - #548

Merged
keepsimple1 merged 6 commits into
mainfrom
fix/issue-545-hostname-rename-loop
Nov 15, 2026
Merged

keepsimple1 merged 6 commits into
mainfrom
fix/issue-545-hostname-rename-loop

Conversation

@keepsimple1

@keepsimple1 keepsimple1 commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

This PR is to address #545.

The loop

An example with the addresses from the issue. The host device-12345.local. has four addresses on wlan0:

Address Type
192.0.2.10 A
fe80::a:2 (link-local) AAAA
2001:db8::a:1 (SLAAC) AAAA
2001:db8::100 (DHCPv6) AAAA

Setup. The IPv4 and link-local addresses come up first. They finish probing and move to active. The two global addresses come up 5 seconds later and start a new probe for the same hostname. While that probe runs, an AAAA answer for device-12345.local. arrives with an address that is not one of the two being probed. That is all the old conflict_handler needs to see a conflict. The answer renames the host to device-12346.local.. Only records still in probing move, so the probe for device-12346.local. has just the two global AAAA records. name_changes maps device-12345.local. to device-12346.local., and the services stay Announced.

Then:

  1. The daemon probes device-12346.local. with 2001:db8::a:1 and 2001:db8::100 in the authority section.
  2. Multicast loopback brings the probe back to the daemon. The services are Announced, and their hostname now resolves to device-12346.local., so the daemon answers with all four addresses. The old answer_hostname_question takes the addresses from each service's own address list and checks only the service's status, never whether the address records are still being probed. So the two global addresses go out too, although their probe is the one in progress.
  3. Loopback brings that answer back to conflict_handler. device-12346.local. is being probed, so each answer record is compared with the probe:
    • A 192.0.2.10: the probe has no A record, so there is nothing to compare with.
    • AAAA 2001:db8::a:1 and 2001:db8::100: they are in the probe, so no conflict.
    • AAAA fe80::a:2: it is not in the probe, so this counts as a conflict, and both AAAA records in the probe move to device-12347.local..
  4. The probe for device-12347.local. again has just the two global addresses, so it goes back to step 1.

The renames never stop. In the issue #545 they ran at about 5 per second for more than 8 hours. No NameChange event is sent, because no probe ever finishes.

Why it needs two addresses of one family. A conflict needs an answer address that the probe lacks while the probe holds another address of the same type, like fe80::a:2 in step 3. With only one IPv6 address, the probe either has it (a match) or has no AAAA record at all (nothing to rename, like the A record). Then the loop can't start.

With this PR:

  • In the setup, the rename also moves the records from active, so the probe for device-12346.local. has all four addresses. Both services go back to Probing until the new probes finish, and are then announced under device-12346.local..
  • In step 2, the daemon doesn't answer for a service that is probing, or with an address that is still being probed, so it sends nothing.
  • In step 3, fe80::a:2 is one of our own addresses, so even if such an answer arrives, it is not a conflict.

Changes

  • Don't answer with an address that is still being probed (RFC 6762 §8.1). answer_hostname_question leaves out addresses that are in the probe for that hostname. When all of them are probing, it answers nothing, not even NSEC.
  • Our own address is not a conflict (RFC 6762 §9). conflict_handler ignores an A/AAAA answer when one of our services publishes that address for the hostname, original or renamed (is_own_address). An address of the interface itself is deliberately not enough, because another responder on the same host can claim the hostname with it. The integration conflict tests depend on that.
  • A hostname conflict moves all of the host's address records: A and AAAA, from both probing and active, so the host isn't split between two names and the new probe has all of its addresses.
  • A rename moves the affected services back to Probing. These are the services waiting on the probe, and for a hostname every service on the host. They wait on the new probes, and are announced under the new names when those finish. Before, they stayed Announced: they kept answering with records that were no longer valid or not probed yet, and probing_handler skipped them as already announced, so they were never announced under the new names.
  • Service answers leave out records still being probed (RFC 6762 §8.1). A PTR answer leaves out an instance whose SRV or TXT record is still being probed, and the additional address records still being probed. Direct SRV and TXT answers do the same.
  • Direct SRV answers use the renamed hostname. add_answer_of_service used the original hostname for the SRV target and its additional address records, while announcements and PTR answers used the renamed one.

Tests

  • Socket-free unit tests: test_answer_hostname_question_skips_probing_addresses, test_is_own_address, test_add_answer_of_service_skips_probing_records, test_ptr_answer_skips_probing_records and test_srv_answer_uses_renamed_hostname.
  • test_own_answer_is_not_a_hostname_conflict: replays the issue on loopback. A peer causes a rename, which moves the service back to Probing. Our own answer with an address the new probe lacks doesn't cause another rename, and a real peer still does.
  • test_hostname_conflict_reannounces_services: two services on one host. The probe of a new address hits a conflict, both services go back to Probing, and they are announced again with the new hostname in their SRV records.
  • The existing conflict tests in tests/mdns_test.rs pass.

Not changed

  • hostname_change() still reads a trailing -<digits> as a counter, so device-012345 becomes device-12346, as the issue notes.

After a hostname rename, the daemon answered its own probe for the new
name, because the services stay announced and `name_changes` already
points at the new name. When the probe held only some of the host's
addresses of one family, the answer had an address the probe lacked, so
`conflict_handler` saw a conflict and renamed the host again, with the
same subset of addresses. This repeated without end.

- Don't answer with an address record that is still being probed
  (RFC 6762 section 8.1).
- Don't treat an answer as a conflict when one of our services
  publishes that address for the hostname (RFC 6762 section 9).
- On a hostname conflict, move all address records of the host (A and
  AAAA, probing and active) to the new name, so the host isn't split
  between two names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
keepsimple1 and others added 5 commits November 14, 2026 10:15
A rename in `conflict_handler` changed the records of the services but
left them `Announced`. They kept answering with records that were no
longer valid or not probed yet, and `probing_handler` skipped them when
the new probes finished, so they were never announced under the new
names.

On a rename, the services waiting on the probe go back to `Probing` and
wait on the new probes. For a hostname, that is every service on the
host, including ones whose records were already active.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RFC 6762 section 8.1: a responder must not answer with a record until
its probe has finished. Address answers already follow this. Service
answers now do too:

- A PTR answer leaves out an instance whose SRV or TXT record is still
  being probed, and the additional address records still being probed.
- A direct SRV or TXT answer leaves out a record still being probed,
  and so do its additional address records.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`add_answer_of_service` used the original hostname for the SRV target
and its additional address records. After a hostname rename, a direct
SRV query got a hostname the daemon no longer answers address queries
for. Use the renamed hostname, as announcements and PTR answers do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@keepsimple1
keepsimple1 merged commit bebe19f into main Nov 15, 2026
6 checks passed
@keepsimple1
keepsimple1 deleted the fix/issue-545-hostname-rename-loop branch November 15, 2026 05:15
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.

1 participant