From 74ac033db10b6c82b4d0fdce2d3b0ef57ac31325 Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Thu, 3 Nov 2022 21:44:01 +0800 Subject: [PATCH] server: fix deadlock when call `killNonFlashbackConn` (#38872) close pingcap/tidb#38862 --- DEPS.bzl | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- server/server.go | 10 +++++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index e9ccd20301ea6..6165078e5d9ff 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -3469,8 +3469,8 @@ def go_deps(): name = "com_github_tikv_client_go_v2", build_file_proto_mode = "disable_global", importpath = "github.com/tikv/client-go/v2", - sum = "h1:NvQHWk0GeXSLEBbmGMPnDMc0to0a3ogzgIRbTKw8MHI=", - version = "v2.0.1-0.20221031063202-30e803b7082c", + sum = "h1:x5L32xr5KE2C0UhlKfrsDTWQ/8fpFYQLq5xn+ph0sQ0=", + version = "v2.0.3-0.20221103084528-ec1202a9d26f", ) go_repository( name = "com_github_tikv_pd_client", diff --git a/go.mod b/go.mod index 576f3d74d0c1a..41fb7aa9d4a27 100644 --- a/go.mod +++ b/go.mod @@ -85,7 +85,7 @@ require ( github.com/stretchr/testify v1.8.0 github.com/tdakkota/asciicheck v0.1.1 github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 - github.com/tikv/client-go/v2 v2.0.1-0.20221031063202-30e803b7082c + github.com/tikv/client-go/v2 v2.0.3-0.20221103084528-ec1202a9d26f github.com/tikv/pd/client v0.0.0-20221031025758-80f0d8ca4d07 github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144 github.com/twmb/murmur3 v1.1.3 diff --git a/go.sum b/go.sum index 65a2845209c37..0b15dbe804918 100644 --- a/go.sum +++ b/go.sum @@ -909,8 +909,8 @@ github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpR github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3/go.mod h1:ON8b8w4BN/kE1EOhwT0o+d62W65a6aPw1nouo9LMgyY= github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJfDRtkanvQPiooDH8HvJ2FBh+iKT/OmiQQ= github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU= -github.com/tikv/client-go/v2 v2.0.1-0.20221031063202-30e803b7082c h1:NvQHWk0GeXSLEBbmGMPnDMc0to0a3ogzgIRbTKw8MHI= -github.com/tikv/client-go/v2 v2.0.1-0.20221031063202-30e803b7082c/go.mod h1:X9s4ct/MLk1sFqe5mU79KClKegLFDTa/FCx3hzexGtk= +github.com/tikv/client-go/v2 v2.0.3-0.20221103084528-ec1202a9d26f h1:x5L32xr5KE2C0UhlKfrsDTWQ/8fpFYQLq5xn+ph0sQ0= +github.com/tikv/client-go/v2 v2.0.3-0.20221103084528-ec1202a9d26f/go.mod h1:X9s4ct/MLk1sFqe5mU79KClKegLFDTa/FCx3hzexGtk= github.com/tikv/pd/client v0.0.0-20221031025758-80f0d8ca4d07 h1:ckPpxKcl75mO2N6a4cJXiZH43hvcHPpqc9dh1TmH1nc= github.com/tikv/pd/client v0.0.0-20221031025758-80f0d8ca4d07/go.mod h1:CipBxPfxPUME+BImx9MUYXCnAVLS3VJUr3mnSJwh40A= github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144 h1:kl4KhGNsJIbDHS9/4U9yQo1UcPQM0kOMJHn29EoH/Ro= diff --git a/server/server.go b/server/server.go index 408594bb696b8..eb1f3d6ec951d 100644 --- a/server/server.go +++ b/server/server.go @@ -949,20 +949,24 @@ func (s *Server) CheckOldRunningTxn(job2ver map[int64]int64, job2ids map[int64]s // KillNonFlashbackClusterConn implements SessionManager interface. func (s *Server) KillNonFlashbackClusterConn() { s.rwlock.RLock() - defer s.rwlock.RUnlock() + connIDs := make([]uint64, 0, len(s.clients)) for _, client := range s.clients { if client.ctx.Session != nil { processInfo := client.ctx.Session.ShowProcess() ddl, ok := processInfo.StmtCtx.GetPlan().(*core.DDL) if !ok { - s.Kill(client.connectionID, false) + connIDs = append(connIDs, client.connectionID) continue } _, ok = ddl.Statement.(*ast.FlashBackToTimestampStmt) if !ok { - s.Kill(client.connectionID, false) + connIDs = append(connIDs, client.connectionID) continue } } } + s.rwlock.RUnlock() + for _, id := range connIDs { + s.Kill(id, false) + } }