Skip to content

Commit

Permalink
Merge pull request #130607 from cockroachdb/blathers/backport-release…
Browse files Browse the repository at this point in the history
…-24.2-130590

release-24.2: util: fix race in cidr startup
  • Loading branch information
andrewbaptist authored Sep 12, 2024
2 parents db161e3 + 896f2fc commit f6888ce
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/util/cidr/cidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,28 @@ func NewLookup(st *settings.Values) *Lookup {
byLength := make([]map[string]string, 0)
c.byLength.Store(&byLength)
c.lastUpdate.Store(time.Time{})
c.changed = make(chan time.Duration)
c.changed = make(chan time.Duration, 1)

cidrMappingUrl.SetOnChange(st, func(ctx context.Context) {
log.Infof(ctx, "url changed to '%s'", cidrMappingUrl.Get(st))
// Reset the lastUpdate time so that the URL is always reloaded even if
// the new file/URL has an older timestamp.
c.lastUpdate.Store(time.Time{})
c.changed <- cidrRefreshInterval.Get(c.st)
select {
case c.changed <- cidrRefreshInterval.Get(c.st):
default:
}
})
// We have to register this callback first. Otherwise we may run into
// an unlikely but possible scenario where we've started the ticker,
// and the setting is changed before we register the callback and the
// ticker will not be reset to the new value.
cidrRefreshInterval.SetOnChange(c.st, func(ctx context.Context) {
log.Infof(ctx, "refresh interval changed to '%s'", cidrRefreshInterval.Get(c.st))
c.changed <- cidrRefreshInterval.Get(c.st)
select {
case c.changed <- cidrRefreshInterval.Get(c.st):
default:
}
})
return c
}
Expand Down

0 comments on commit f6888ce

Please sign in to comment.