From d663cde620046201ce9b81505a91cc419cbea0f4 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 20 Oct 2025 19:58:23 +0000 Subject: [PATCH 1/2] Fix typo in create_function_stmt.go comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Corrected "Undertand" to "Understand" in the TODO comment for the CreateFunctionStmt struct fields. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- internal/sql/ast/create_function_stmt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/sql/ast/create_function_stmt.go b/internal/sql/ast/create_function_stmt.go index a1e0b8f728..86605344f7 100644 --- a/internal/sql/ast/create_function_stmt.go +++ b/internal/sql/ast/create_function_stmt.go @@ -5,7 +5,7 @@ type CreateFunctionStmt struct { Params *List ReturnType *TypeName Func *FuncName - // TODO: Undertand these two fields + // TODO: Understand these two fields Options *List WithClause *List } From 0ecf5b7fc1a269ce7b5c576701a2e099e39b47de Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 20 Oct 2025 20:12:06 +0000 Subject: [PATCH 2/2] Fix race condition in database client initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed a race condition in the checker's Client field initialization by using sync.Once to ensure thread-safe, single initialization even when fetchDatabaseUri is called concurrently. Changes: - Added sync.Once field (clientOnce) to checker struct - Replaced check-then-act pattern with sync.Once.Do() - Removed FIXME comment as issue is now resolved This ensures that even if multiple goroutines call fetchDatabaseUri simultaneously, the Client will only be initialized once without any race conditions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- internal/cmd/vet.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/cmd/vet.go b/internal/cmd/vet.go index 8a7f8077db..fe3ece38f3 100644 --- a/internal/cmd/vet.go +++ b/internal/cmd/vet.go @@ -14,6 +14,7 @@ import ( "runtime/trace" "slices" "strings" + "sync" "time" _ "github.com/go-sql-driver/mysql" @@ -386,6 +387,7 @@ type checker struct { Stderr io.Writer OnlyManagedDB bool Client dbmanager.Client + clientOnce sync.Once Replacer *shfmt.Replacer } @@ -402,11 +404,10 @@ func (c *checker) fetchDatabaseUri(ctx context.Context, s config.SQL) (string, f return uri, cleanup, err } - if c.Client == nil { - // FIXME: Eventual race condition - client := dbmanager.NewClient(c.Conf.Servers) - c.Client = client - } + // Initialize the client exactly once, even if called concurrently + c.clientOnce.Do(func() { + c.Client = dbmanager.NewClient(c.Conf.Servers) + }) var ddl []string files, err := sqlpath.Glob(s.Schema)