Skip to content

Commit 9d976cb

Browse files
craig[bot]rafiss
andcommitted
107459: sql: fix potential mutex leak in conn_executor r=rafiss a=rafiss This was very unlikely to cause issues, since the leak could only happen if an assertion error occurred, and we haven't heard of those happening here. informs: cockroachdb#107433 Release note: None Co-authored-by: Rafi Shamim <[email protected]>
2 parents eb0a104 + eee10b1 commit 9d976cb

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

pkg/sql/conn_executor.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2922,13 +2922,18 @@ func (ex *connExecutor) execCopyOut(
29222922
}
29232923

29242924
if copyErr := ex.execWithProfiling(ctx, cmd.Stmt, nil, func(ctx context.Context) error {
2925-
ex.mu.Lock()
2926-
queryMeta, ok := ex.mu.ActiveQueries[queryID]
2927-
if !ok {
2928-
return errors.AssertionFailedf("query %d not in registry", queryID)
2925+
if err := func() error {
2926+
ex.mu.Lock()
2927+
defer ex.mu.Unlock()
2928+
queryMeta, ok := ex.mu.ActiveQueries[queryID]
2929+
if !ok {
2930+
return errors.AssertionFailedf("query %d not in registry", queryID)
2931+
}
2932+
queryMeta.phase = executing
2933+
return nil
2934+
}(); err != nil {
2935+
return err
29292936
}
2930-
queryMeta.phase = executing
2931-
ex.mu.Unlock()
29322937

29332938
// We'll always have a txn on the planner since we called resetPlanner
29342939
// above.
@@ -3185,13 +3190,18 @@ func (ex *connExecutor) execCopyIn(
31853190
}
31863191

31873192
if copyErr = ex.execWithProfiling(ctx, cmd.Stmt, nil, func(ctx context.Context) error {
3188-
ex.mu.Lock()
3189-
queryMeta, ok := ex.mu.ActiveQueries[queryID]
3190-
if !ok {
3191-
return errors.AssertionFailedf("query %d not in registry", queryID)
3193+
if err := func() error {
3194+
ex.mu.Lock()
3195+
defer ex.mu.Unlock()
3196+
queryMeta, ok := ex.mu.ActiveQueries[queryID]
3197+
if !ok {
3198+
return errors.AssertionFailedf("query %d not in registry", queryID)
3199+
}
3200+
queryMeta.phase = executing
3201+
return nil
3202+
}(); err != nil {
3203+
return err
31923204
}
3193-
queryMeta.phase = executing
3194-
ex.mu.Unlock()
31953205
return cm.run(ctx)
31963206
}); copyErr != nil {
31973207
// TODO(andrei): We don't have a full retriable error story for the copy machine.

0 commit comments

Comments
 (0)