From 304cece9dee478577733bb10fa0b552c4493ff5b Mon Sep 17 00:00:00 2001 From: Yanhu007 Date: Tue, 14 Apr 2026 08:09:33 +0800 Subject: [PATCH] fix: merge address info when aliasing existing entries 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 #145 --- client.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index c9806fb..4a0a90f 100644 --- a/client.go +++ b/client.go @@ -464,8 +464,22 @@ func ensureName(inprogress map[string]*ServiceEntry, name string) *ServiceEntry return inp } -// alias is used to setup an alias between two entries +// alias is used to setup an alias between two entries. +// When the destination already has an entry (e.g. an A record arrived +// before the SRV record), merge its address information into the source +// entry so that nothing is lost. func alias(inprogress map[string]*ServiceEntry, src, dst string) { srcEntry := ensureName(inprogress, src) + if dstEntry, ok := inprogress[dst]; ok && dstEntry != srcEntry { + // Merge address info from the existing destination entry + if srcEntry.AddrV4 == nil && dstEntry.AddrV4 != nil { + srcEntry.Addr = dstEntry.Addr + srcEntry.AddrV4 = dstEntry.AddrV4 + } + if srcEntry.AddrV6IPAddr == nil && dstEntry.AddrV6IPAddr != nil { + srcEntry.AddrV6 = dstEntry.AddrV6 + srcEntry.AddrV6IPAddr = dstEntry.AddrV6IPAddr + } + } inprogress[dst] = srcEntry }