From e13b08842e566f71395d0f22d5623e8e112118c6 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 26 Nov 2021 23:58:39 +0800 Subject: [PATCH] executer: fix data race Signed-off-by: Weizhen Wang --- executor/builder.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/executor/builder.go b/executor/builder.go index 33f5c29085e16..3588a80bfd75f 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -4698,20 +4698,20 @@ func (b *executorBuilder) getCacheTable(tblInfo *model.TableInfo, startTS uint64 b.ctx.GetSessionVars().StmtCtx.ReadFromTableCache = true return cacheData } - go func() { - defer func() { - if r := recover(); r != nil { - logutil.BgLogger().Error("panic in the recoverable goroutine", - zap.Reflect("r", r), - zap.Stack("stack trace")) - } - }() - if !b.ctx.GetSessionVars().StmtCtx.InExplainStmt && !b.inDeleteStmt && !b.inUpdateStmt { + if !b.ctx.GetSessionVars().StmtCtx.InExplainStmt && !b.inDeleteStmt && !b.inUpdateStmt { + go func() { + defer func() { + if r := recover(); r != nil { + logutil.BgLogger().Error("panic in the recoverable goroutine", + zap.Reflect("r", r), + zap.Stack("stack trace")) + } + }() err := tbl.(table.CachedTable).UpdateLockForRead(b.ctx.GetStore(), startTS) if err != nil { log.Warn("Update Lock Info Error") } - } - }() + }() + } return nil }