Skip to content

Commit 6d94042

Browse files
committed
sqlproxyccl: simplify NewSubStopper
The lock in NewSubStopper caused lock ordering warnings when run under deadlock detection. The justification given for the lock's existence is wrong. If a closer is added to an already stopped stopper, the closer is called immediately. Release note: None Fixes: cockroachdb#106571
1 parent 261e785 commit 6d94042

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

pkg/ccl/sqlproxyccl/tenantdirsvr/test_directory_svr.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,12 @@ import (
2929
var _ tenant.DirectoryServer = (*TestDirectoryServer)(nil)
3030

3131
// NewSubStopper creates a new stopper that will be stopped when either the
32-
// parent is stopped or its own Stop is called. The code is slightly more
33-
// complicated that simply calling NewStopper followed by AddCloser since there
34-
// is a possibility that between the two calls, the parent stopper completes a
35-
// stop and then the leak detection may find a leaked stopper.
32+
// parent is stopped or its own Stop is called.
3633
func NewSubStopper(parentStopper *stop.Stopper) *stop.Stopper {
37-
var mu syncutil.Mutex
38-
var subStopper *stop.Stopper
34+
subStopper := stop.NewStopper(stop.WithTracer(parentStopper.Tracer()))
3935
parentStopper.AddCloser(stop.CloserFn(func() {
40-
mu.Lock()
41-
defer mu.Unlock()
42-
if subStopper == nil {
43-
subStopper = stop.NewStopper(stop.WithTracer(parentStopper.Tracer()))
44-
}
4536
subStopper.Stop(context.Background())
4637
}))
47-
mu.Lock()
48-
defer mu.Unlock()
49-
if subStopper == nil {
50-
subStopper = stop.NewStopper(stop.WithTracer(parentStopper.Tracer()))
51-
}
5238
return subStopper
5339
}
5440

0 commit comments

Comments
 (0)