From 443f461be9aa69c0851dac26c751553ed04ed87b Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 15 Dec 2024 20:50:13 +0100 Subject: [PATCH] Fix excess error message during writes Fixes #2290 Signed-off-by: Kristoffer Dalby --- hscontrol/dns/extrarecords.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hscontrol/dns/extrarecords.go b/hscontrol/dns/extrarecords.go index 73f646ba98..d9b39bfe77 100644 --- a/hscontrol/dns/extrarecords.go +++ b/hscontrol/dns/extrarecords.go @@ -116,6 +116,11 @@ func (e *ExtraRecordsMan) updateRecords() { return } + // If there are no records, ignore the update. + if records == nil { + return + } + e.mu.Lock() defer e.mu.Unlock() @@ -143,6 +148,12 @@ func readExtraRecordsFromPath(path string) ([]tailcfg.DNSRecord, [32]byte, error return nil, [32]byte{}, fmt.Errorf("reading path: %s, err: %w", path, err) } + // If the read was triggered too fast, and the file is not complete, ignore the update + // if the file is empty. A consecutive update will be triggered when the file is complete. + if len(b) == 0 { + return nil, [32]byte{}, nil + } + var records []tailcfg.DNSRecord err = json.Unmarshal(b, &records) if err != nil {