Skip to content

Commit

Permalink
instancestorage: ensure that the cache goroutine shuts down gracefully
Browse files Browse the repository at this point in the history
`(*stop.Stopper).AddCloser` registers a closer to be called after all
async tasks have exited. The cache was running, waiting to be closed.
We instead need to hook up its context to exit when the stopper is
quiescing.

Epic: none

Release note: None
  • Loading branch information
ajwerner committed Mar 14, 2023
1 parent a902d6a commit 358f86d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/sql/sqlinstance/instancestorage/instancereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,19 @@ func (r *Reader) Start(ctx context.Context, self sqlinstance.InstanceInfo) {
timestamp: hlc.Timestamp{}, // intentionally zero
},
})
// Make sure that the reader shuts down gracefully.
ctx, cancel := r.stopper.WithCancelOnQuiesce(ctx)
err := r.stopper.RunAsyncTask(ctx, "start-instance-reader", func(ctx context.Context) {
cache, err := r.storage.newInstanceCache(ctx)
if err != nil {
r.setInitialScanDone(err)
return
}
r.stopper.AddCloser(cache)
r.setCache(cache)
r.setInitialScanDone(nil)
})
if err != nil {
cancel()
r.setInitialScanDone(err)
}
}
Expand Down

0 comments on commit 358f86d

Please sign in to comment.