Skip to content

Commit

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

release-24.2.3-rc: util: fix race in cidr startup
  • Loading branch information
andrewbaptist committed Sep 12, 2024
2 parents ad8fa9c + 27e45b9 commit 30871f7
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 30871f7

Please sign in to comment.