From 80fc05611cd472c5408e23fb3dad2d4d2cf39e88 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Fri, 9 Aug 2024 21:50:27 +0800 Subject: [PATCH] variable: fix data race in `GetTemporaryTable` --- pkg/sessionctx/variable/session.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/sessionctx/variable/session.go b/pkg/sessionctx/variable/session.go index b17e71be13ec7..0121535e995e0 100644 --- a/pkg/sessionctx/variable/session.go +++ b/pkg/sessionctx/variable/session.go @@ -2765,6 +2765,8 @@ func (s *SessionVars) GetDivPrecisionIncrement() int { // GetTemporaryTable returns a TempTable by tableInfo. func (s *SessionVars) GetTemporaryTable(tblInfo *model.TableInfo) tableutil.TempTable { if tblInfo.TempTableType != model.TempTableNone { + s.TxnCtxMu.Lock() + defer s.TxnCtxMu.Unlock() if s.TxnCtx.TemporaryTables == nil { s.TxnCtx.TemporaryTables = make(map[int64]tableutil.TempTable) }