Skip to content

Commit 9bb7b8b

Browse files
committed
lock source.refresh
1 parent 3ba850c commit 9bb7b8b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

dnscrypt-proxy/sources.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,16 @@ func (source *Source) fetchWithCache(xTransport *XTransport) (time.Duration, err
177177
return 0, err
178178
}
179179
if ttl > 0 {
180+
source.Lock()
180181
source.refresh = now.Add(ttl)
182+
source.Unlock()
181183
return 0, err
182184
}
183185

184186
ttl = MinimumPrefetchInterval
187+
source.Lock()
185188
source.refresh = now.Add(ttl)
189+
source.Unlock()
186190
var bin, sig []byte
187191
for _, srcURL := range source.urls {
188192
dlog.Infof("Source [%s] loading from URL [%s]", source.name, srcURL)
@@ -208,7 +212,9 @@ func (source *Source) fetchWithCache(xTransport *XTransport) (time.Duration, err
208212
}
209213
source.updateCache(bin, sig)
210214
ttl = source.prefetchDelay
215+
source.Lock()
211216
source.refresh = now.Add(ttl)
217+
source.Unlock()
212218
return ttl, nil
213219
}
214220

@@ -264,7 +270,10 @@ func PrefetchSources(xTransport *XTransport, sources []*Source) time.Duration {
264270
now := getCurrentTime()
265271
interval := MinimumPrefetchInterval
266272
for _, source := range sources {
267-
if source.refresh.IsZero() || source.refresh.After(now) {
273+
source.RLock()
274+
refresh := source.refresh
275+
source.RUnlock()
276+
if refresh.IsZero() || refresh.After(now) {
268277
continue
269278
}
270279
dlog.Debugf("Prefetching [%s]", source.name)

0 commit comments

Comments
 (0)