Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql/gcjob/gcjobnotifier: fix rare panic #80551

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/sql/gcjob/gcjobnotifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ func (n *Notifier) AddNotifyee(ctx context.Context) (onChange <-chan struct{}, c
if n.mu.deltaFilter == nil {
zoneCfgFilter := gossip.MakeSystemConfigDeltaFilter(n.prefix)
n.mu.deltaFilter = &zoneCfgFilter
// Initialize the filter with the current values.
n.mu.deltaFilter.ForModified(n.provider.GetSystemConfig(), func(kv roachpb.KeyValue) {})
// Initialize the filter with the current values, if they exist.
cfg := n.provider.GetSystemConfig()
if cfg != nil {
n.mu.deltaFilter.ForModified(cfg, func(kv roachpb.KeyValue) {})
}
}
c := make(chan struct{}, 1)
n.mu.notifyees[c] = struct{}{}
Expand Down
17 changes: 17 additions & 0 deletions pkg/sql/gcjob/gcjobnotifier/notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ func TestNotifier(t *testing.T) {
n.AddNotifyee(ctx)
})
})
t.Run("safe to on AddNotifyee after start before config", func(t *testing.T) {
ch := make(chan struct{}, 1)
cfg := mkSystemConfig(mkZoneConfigKV(1, 1, "1"))
p := &testingProvider{ch: ch}
n := New(settings, p, keys.SystemSQLCodec, stopper)
n.Start(ctx)
n1Ch, cleanup := n.AddNotifyee(ctx)
defer cleanup()
select {
case <-time.After(10 * time.Millisecond):
case <-n1Ch:
t.Fatal("should not have gotten notified")
}
p.setSystemConfig(cfg)
ch <- struct{}{}
<-n1Ch
})
t.Run("notifies on changed delta and cleanup", func(t *testing.T) {
cfg := config.NewSystemConfig(zonepb.DefaultSystemZoneConfigRef())
cfg.Values = []roachpb.KeyValue{
Expand Down