From 25dcdb6f7669c0f809f9157abd8ea29e6b9ed530 Mon Sep 17 00:00:00 2001 From: rharding6373 Date: Sat, 26 Mar 2022 08:51:32 -0700 Subject: [PATCH] sqlsmith: fix deadlock during generation Fixes a deadlock when sqlsmith generates join expressions. Fixes: #78555 Release note: None --- pkg/internal/sqlsmith/relational.go | 2 ++ pkg/internal/sqlsmith/type.go | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/internal/sqlsmith/relational.go b/pkg/internal/sqlsmith/relational.go index 67e136d12c05..e66ef908d520 100644 --- a/pkg/internal/sqlsmith/relational.go +++ b/pkg/internal/sqlsmith/relational.go @@ -206,6 +206,8 @@ func makeEquiJoinExpr(s *Smither, refs colRefs, forJoin bool) (tree.TableExpr, c return nil, nil, false } + s.lock.RLock() + defer s.lock.RUnlock() // Determine overlapping types. var available [][2]tree.TypedExpr for _, leftCol := range leftRefs { diff --git a/pkg/internal/sqlsmith/type.go b/pkg/internal/sqlsmith/type.go index 3dddb02ecc00..4dfd4490ea2e 100644 --- a/pkg/internal/sqlsmith/type.go +++ b/pkg/internal/sqlsmith/type.go @@ -59,9 +59,9 @@ func (s *Smither) randScalarType() *types.T { // isScalarType returns true if t is a member of types.Scalar, or a user defined // enum. +// Requires s.lock to be held. func (s *Smither) isScalarType(t *types.T) bool { - s.lock.RLock() - defer s.lock.RUnlock() + s.lock.AssertRHeld() scalarTypes := types.Scalar if s.types != nil { scalarTypes = s.types.scalarTypes