From 048261c921240a537a172397807e6de6494a7aa5 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 16 Jun 2015 13:06:14 +0100 Subject: [PATCH] Hold lock while accessing mutable variable, but release before sending on chan --- nameserver/zone_lookup.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nameserver/zone_lookup.go b/nameserver/zone_lookup.go index 940ebc08..cc1f3336 100644 --- a/nameserver/zone_lookup.go +++ b/nameserver/zone_lookup.go @@ -235,15 +235,18 @@ func (zone *ZoneDb) DomainLookupInaddr(inaddr string) (res []ZoneRecord, err err func (zone *ZoneDb) startUpdatingName(name string) { if zone.refreshInterval > 0 { zone.mx.Lock() + // check if we should enqueue a refresh request for this name n := zone.getNameSet(defaultRemoteIdent).getName(name, true) - now := zone.clock.Now() - zone.mx.Unlock() // Don't hold the lock while talking to the SchedQueue if n.lastRefreshTime.IsZero() { + now := zone.clock.Now() n.lastRefreshTime = now + zone.mx.Unlock() Debug.Printf("[zonedb] Creating new immediate refresh request for '%s'", name) zone.refreshScheds.Add(func() time.Time { return zone.updater(name) }, now) + } else { + zone.mx.Unlock() } } }