Skip to content

fix: merge address info when aliasing entries to handle out-of-order DNS records#151

Open
Yanhu007 wants to merge 1 commit intohashicorp:mainfrom
Yanhu007:fix/service-discovery-record-order
Open

fix: merge address info when aliasing entries to handle out-of-order DNS records#151
Yanhu007 wants to merge 1 commit intohashicorp:mainfrom
Yanhu007:fix/service-discovery-record-order

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #145

Problem

When DNS records arrive in certain orders (A/AAAA before SRV), the alias function overwrites an existing entry that already has an IP address with the SRV entry that only has port/host info. The IP address is lost, and the entry never becomes complete.

Example failure sequence:

  1. PTR → creates entry
  2. A record for device.local. → creates entry with IP
  3. SRV for device._service._tcp.local. with target device.local.alias() overwrites the A-record entry, losing the IP
  4. Entry never completes because it has port but no IP

This was reported with Alfen EV Chargers but affects any device that sends A/AAAA records before SRV records.

Fix

In alias(), when the destination key already has an entry with address information, merge the addresses into the source entry before overwriting the map entry.

Testing

All existing tests pass.

When A/AAAA records arrive before SRV records, the alias function
overwrites the existing entry (which has the IP address) with the
SRV's entry (which has the port), losing the address information.
This causes the service entry to never become complete, and the
service is not discovered.

Now when the alias destination already has an entry with address
information, merge it into the source entry before overwriting.
This handles out-of-order DNS record delivery, as seen with
devices like the Alfen EV Charger.

Fixes hashicorp#145
@Yanhu007 Yanhu007 requested review from a team as code owners April 14, 2026 00:09
@hashicorp-cla-app
Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

1 similar comment
@hashicorp-cla-app
Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

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.

Service discovery fails when A/AAAA records arrive before SRV records - entries incorrectly marked as incomplete

1 participant