You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At line 744 we use h.mu.ctx to execute internal sql without h.mu.Lock(). h.mu.Lock() is needed because we only allow h.mu.ctx executing one statement at a time. Without h.mu.Lock(), data race may occur when h.mu.ctx executes two statements concurrently.
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
Just run TiDB server. Maybe turning on stats feedback feature make it easier to reproduce.
tidb/statistics/handle/update.go
Lines 728 to 747 in 9c4f94d
At line 744 we use
h.mu.ctx
to execute internal sql withouth.mu.Lock()
.h.mu.Lock()
is needed because we only allowh.mu.ctx
executing one statement at a time. Withouth.mu.Lock()
, data race may occur whenh.mu.ctx
executes two statements concurrently.2. What did you expect to see? (Required)
No data race.
3. What did you see instead (Required)
Data race happened.
fatal error: concurrent map writes
goroutine 1185 [running]:
runtime.throw(0x3d8e07c, 0x15)
/usr/local/go/src/runtime/panic.go:1117 +0x72 fp=0xc01df45428 sp=0xc01df453f8 pc=0x12b9dd2
runtime.mapassign_fast64(0x38e00c0, 0xc00ec840c0, 0x7, 0x6186720)
/usr/local/go/src/runtime/map_fast64.go:176 +0x325 fp=0xc01df45468 sp=0xc01df45428 pc=0x1294765
github.com/pingcap/tidb/util/execdetails.(*RuntimeStatsColl).RegisterStats(0xc0012b64c8, 0x7, 0x42ba8a8, 0xc077907480)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/execdetails/execdetails.go:591 +0x4be fp=0xc01df45500 sp=0xc01df45468 pc=0x1fe755e
github.com/pingcap/tidb/executor.(*ProjectionExec).Close(0xc01bc47900, 0x0, 0x0)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/projection.go:327 +0x246 fp=0xc01df45568 sp=0xc01df45500 pc=0x331a8c6
github.com/pingcap/tidb/executor.(*SortExec).Close(0xc036d9efc0, 0x3128ea48d406, 0x338b9a5)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/sort.go:81 +0xee fp=0xc01df455a8 sp=0xc01df45568 pc=0x336cf0e
github.com/pingcap/tidb/executor.(*recordSet).Close(0xc03572d220, 0x136, 0xc0933a7718)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:171 +0x38 fp=0xc01df455e8 sp=0xc01df455a8 pc=0x31cceb8
github.com/pingcap/tidb/session.(*execStmtResult).Close(0xc0817faf00, 0x0, 0x68)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:1733 +0x42 fp=0xc01df45648 sp=0xc01df455e8 pc=0x33e57c2
github.com/pingcap/tidb/util/sqlexec.RecordSet.Close-fm(0xc00dfa3900, 0xc036d9efc0)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/sqlexec/restricted_sql_executor.go:147 +0x38 fp=0xc01df45670 sp=0xc01df45648 pc=0x2126658
github.com/pingcap/tidb/parser/terror.Call(0xc01df45910)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/parser/terror/terror.go:298 +0x3f fp=0xc01df457f0 sp=0xc01df45670 pc=0x1c32c9f
github.com/pingcap/tidb/statistics/handle.(*Handle).HandleUpdateStats.func1(0xc0933a79e0, 0xc00e3a0e10, 0x42f9098, 0xc013990d90, 0x0, 0x0)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/handle/update.go:732 +0x787 fp=0xc01df45948 sp=0xc01df457f0 pc=0x2652b07
github.com/pingcap/tidb/statistics/handle.(*Handle).HandleUpdateStats(0xc00e3a0e10, 0x42f9098, 0xc013990d90, 0x0, 0x6)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/handle/update.go:733 +0x126 fp=0xc01df45a00 sp=0xc01df45948 pc=0x26448e6
github.com/pingcap/tidb/domain.(*Domain).updateStatsWorker(0xc00032fe60, 0x4303f18, 0xc00d5fde00, 0x42d70c8, 0xc00e3a0ea0)
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/domain/domain.go:1394 +0x925 fp=0xc01df45fb8 sp=0xc01df45a00 pc=0x28391a5
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:1371 +0x1 fp=0xc01df45fc0 sp=0xc01df45fb8 pc=0x12f5081
created by github.com/pingcap/tidb/domain.(*Domain).UpdateTableStatsLoop
/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/domain/domain.go:1259 +0x1d6
4. What is your TiDB version? (Required)
v5.3.1(I think the problem also exists on master)
The text was updated successfully, but these errors were encountered: