Skip to content

Commit

Permalink
sqlproxyccl: simplify NewSubStopper
Browse files Browse the repository at this point in the history
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: #106571
  • Loading branch information
jeffswenson committed Jul 20, 2023
1 parent 261e785 commit 6d94042
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions pkg/ccl/sqlproxyccl/tenantdirsvr/test_directory_svr.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,12 @@ import (
var _ tenant.DirectoryServer = (*TestDirectoryServer)(nil)

// NewSubStopper creates a new stopper that will be stopped when either the
// parent is stopped or its own Stop is called. The code is slightly more
// complicated that simply calling NewStopper followed by AddCloser since there
// is a possibility that between the two calls, the parent stopper completes a
// stop and then the leak detection may find a leaked stopper.
// parent is stopped or its own Stop is called.
func NewSubStopper(parentStopper *stop.Stopper) *stop.Stopper {
var mu syncutil.Mutex
var subStopper *stop.Stopper
subStopper := stop.NewStopper(stop.WithTracer(parentStopper.Tracer()))
parentStopper.AddCloser(stop.CloserFn(func() {
mu.Lock()
defer mu.Unlock()
if subStopper == nil {
subStopper = stop.NewStopper(stop.WithTracer(parentStopper.Tracer()))
}
subStopper.Stop(context.Background())
}))
mu.Lock()
defer mu.Unlock()
if subStopper == nil {
subStopper = stop.NewStopper(stop.WithTracer(parentStopper.Tracer()))
}
return subStopper
}

Expand Down

0 comments on commit 6d94042

Please sign in to comment.