pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.2k stars 5.84k forks source link

data race in the sessionctx when running ```make race``` #30232

Closed hawkingrei closed 2 years ago

hawkingrei commented 2 years ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

make race

2. What did you expect to see? (Required)

None

3. What did you see instead (Required)

 WARNING: DATA RACE
Write at 0x00c0017ae938 by goroutine 37:
  github.com/pingcap/tidb/sessionctx/variable.(*SessionVars).InitStatementContext()
      /go/tidb/sessionctx/variable/session.go:970 +0x3416
  github.com/pingcap/tidb/executor.ResetContextOfStmt()
      /go/tidb/executor/executor.go:1685 +0x3470
  github.com/pingcap/tidb/session.(*session).ExecuteStmt()
      /go/tidb/session/session.go:1534 +0x204
  github.com/pingcap/tidb/testkit.(*TestKit).Exec()
      /go/tidb/testkit/testkit.go:145 +0x2dc
  github.com/pingcap/tidb/testkit.(*TestKit).MustExec()
      /go/tidb/testkit/testkit.go:77 +0x96
  github.com/pingcap/tidb/infoschema_test.TestStmtSummaryErrorCount()
      /go/tidb/infoschema/tables_serial_test.go:1052 +0x3bc
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:1193 +0x202
Previous read at 0x00c0017ae938 by goroutine 98:
  sync/atomic.LoadInt32()
      /usr/local/go/src/runtime/race_amd64.s:213 +0xb
  sync.(*Once).Do()
      /usr/local/go/src/sync/once.go:57 +0x3a
  github.com/pingcap/tidb/sessionctx/stmtctx.(*StatementContext).SQLDigest()
      /go/tidb/sessionctx/stmtctx/stmtctx.go:268 +0x68
  github.com/pingcap/tidb/sessionctx/stmtctx.(*StatementContext).GetResourceGroupTagByLabel()
      /go/tidb/sessionctx/stmtctx/stmtctx.go:302 +0x45
  github.com/pingcap/tidb/sessionctx/stmtctx.(*StatementContext).GetResourceGroupTagger.func1()
      /go/tidb/sessionctx/stmtctx/stmtctx.go:292 +0xa4
  github.com/tikv/client-go/v2/txnkv/transaction.actionCleanup.handleSingleBatch()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211118154139-b11da6307c6f/txnkv/transaction/cleanup.go:68 +0xe0d
  github.com/tikv/client-go/v2/txnkv/transaction.(*actionCleanup).handleSingleBatch()
      <autogenerated>:1 +0xc4
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).doActionOnBatches()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211118154139-b11da6307c6f/txnkv/transaction/2pc.go:824 +0x169
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).doActionOnGroupMutations()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211118154139-b11da6307c6f/txnkv/transaction/2pc.go:763 +0xc19
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).doActionOnMutations()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211118154139-b11da6307c6f/txnkv/transaction/2pc.go:588 +0x168
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).cleanupMutations()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211118154139-b11da6307c6f/txnkv/transaction/cleanup.go:96 +0x124f
  github.com/tikv/client-go/v2/txnkv/transaction.(*twoPhaseCommitter).cleanup.func1()
      /home/prow/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.0-alpha.0.20211118154139-b11da6307c6f/txnkv/transaction/2pc.go:1107 +0x1045 

4. What is your TiDB version? (Required)

master

hawkingrei commented 2 years ago

close the issue because of stack inaccuracy

github-actions[bot] commented 2 years ago

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.