From 358f86dcd334599bebe965d5640fc3fc72dfa276 Mon Sep 17 00:00:00 2001 From: ajwerner Date: Tue, 14 Mar 2023 00:15:04 -0400 Subject: [PATCH] instancestorage: ensure that the cache goroutine shuts down gracefully `(*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 --- pkg/sql/sqlinstance/instancestorage/instancereader.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/sql/sqlinstance/instancestorage/instancereader.go b/pkg/sql/sqlinstance/instancestorage/instancereader.go index 6c1cc6c6ff97..eb9ff89b93ef 100644 --- a/pkg/sql/sqlinstance/instancestorage/instancereader.go +++ b/pkg/sql/sqlinstance/instancestorage/instancereader.go @@ -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) } }