From 7a106aeb5f56ad278c3268bc7cba72f0754b9de5 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 16 Jun 2015 11:44:25 +0100 Subject: [PATCH 1/2] Release lock before sending on a channel --- nameserver/zone_lookup.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/nameserver/zone_lookup.go b/nameserver/zone_lookup.go index ba4603bc..940ebc08 100644 --- a/nameserver/zone_lookup.go +++ b/nameserver/zone_lookup.go @@ -235,12 +235,11 @@ func (zone *ZoneDb) DomainLookupInaddr(inaddr string) (res []ZoneRecord, err err func (zone *ZoneDb) startUpdatingName(name string) { if zone.refreshInterval > 0 { zone.mx.Lock() - defer zone.mx.Unlock() - // 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 Debug.Printf("[zonedb] Creating new immediate refresh request for '%s'", name) From 048261c921240a537a172397807e6de6494a7aa5 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 16 Jun 2015 13:06:14 +0100 Subject: [PATCH 2/2] 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() } } }