Skip to content

Commit

Permalink
sql/gcjob/gcjobnotifier: fix race
Browse files Browse the repository at this point in the history
The callback which I had assumed could only be called once was being
called multiple times concurrently.

Fixes #86121

Release note: None
  • Loading branch information
ajwerner committed Aug 16, 2022
1 parent a96e3a5 commit 72f4bcc
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/sql/gcjob/gcjobnotifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@ func (n *Notifier) Start(ctx context.Context) {
func (n *Notifier) run(_ context.Context) {
defer n.markStopped()
systemConfigUpdateCh, _ := n.provider.RegisterSystemConfigChannel()
var haveNotified bool
var haveNotified syncutil.AtomicBool
versionSettingChanged := make(chan struct{}, 1)
versionBeingWaited := clusterversion.ByKey(clusterversion.UseDelRangeInGCJob)
n.settings.Version.SetOnChange(func(ctx context.Context, newVersion clusterversion.ClusterVersion) {
if !haveNotified && versionBeingWaited.LessEq(newVersion.Version) {
haveNotified = true
if !haveNotified.Get() &&
versionBeingWaited.LessEq(newVersion.Version) &&
!haveNotified.Swap(true) {
versionSettingChanged <- struct{}{}
}
})
Expand Down

0 comments on commit 72f4bcc

Please sign in to comment.