Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite old DNS results with empty list #1260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lighthouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (lh *LightHouse) addStaticRemotes(i int, d time.Duration, network string, t
ctx := lh.ctx
lh.Unlock()

hr, err := NewHostnameResults(ctx, lh.l, d, network, timeout, toAddrs, func() {
hr, err := NewHostnamesResults(ctx, lh.l, d, vpnIp, network, timeout, toAddrs, func() {
// This callback runs whenever the DNS hostname resolver finds a different set of IP's
// in its resolution for hostnames.
am.Lock()
Expand Down
41 changes: 24 additions & 17 deletions remote_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ type hostnamesResults struct {
network string
lookupTimeout time.Duration
cancelFn func()
l *logrus.Logger
l logrus.FieldLogger
ips atomic.Pointer[map[netip.AddrPort]struct{}]
}

func NewHostnameResults(ctx context.Context, l *logrus.Logger, d time.Duration, network string, timeout time.Duration, hostPorts []string, onUpdate func()) (*hostnamesResults, error) {
func NewHostnamesResults(ctx context.Context, l logrus.FieldLogger, d time.Duration, vpnIp netip.Addr, network string, timeout time.Duration, hostPorts []string, onUpdate func()) (*hostnamesResults, error) {
l = l.WithField("vpnIp", vpnIp)
r := &hostnamesResults{
hostnames: make([]hostnamePort, len(hostPorts)),
network: network,
Expand Down Expand Up @@ -130,27 +131,33 @@ func NewHostnameResults(ctx context.Context, l *logrus.Logger, d time.Duration,
netipAddrs[netip.AddrPortFrom(a.Unmap(), hostPort.port)] = struct{}{}
}
}

origSet := r.ips.Load()
different := false
for a := range *origSet {
if _, ok := netipAddrs[a]; !ok {
different = true
break
}
}
if !different {
for a := range netipAddrs {
if _, ok := (*origSet)[a]; !ok {
if len(netipAddrs) == 0 && len(*origSet) != 0 {
l.WithFields(logrus.Fields{"hostnames": r.hostnames}).Info("No IPs resolved for hostnames, refusing to overwrite existing IPs")
Comment on lines +136 to +137
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure how to behave in this scenario. LookupNetIP is asking the local resolver to either perform the DNS lookup or return its cached results. If it fails, then presumably there are no cached results because the TTL has expired. Should we keep hitting IPs when the TTL from prior queries has expired?
We could consider doing something else - Fast re-query on lookup errors? User could double the DNS lookup timeout? Or, never remove IPs from the list, just keep hitting whatever IPs we learned in the past? (I believe this is how the static IPs work today on reconfigs.)

} else {
different := false
for a := range *origSet {
if _, ok := netipAddrs[a]; !ok {
different = true
break
}
}
if !different {
for a := range netipAddrs {
if _, ok := (*origSet)[a]; !ok {
different = true
break
}
}
}
if different {
l.WithFields(logrus.Fields{"origSet": origSet, "newSet": netipAddrs}).Info("DNS results changed for host list")
r.ips.Store(&netipAddrs)
onUpdate()
}
}
if different {
l.WithFields(logrus.Fields{"origSet": origSet, "newSet": netipAddrs}).Info("DNS results changed for host list")
r.ips.Store(&netipAddrs)
onUpdate()
}

select {
case <-newCtx.Done():
return
Expand Down
Loading