pingcap / pingcap/tidb

TTL returned KILLed session to session pool

Open
#61,862 1 comment 0 reactions 0 assignees View on GitHub
affects-7.1 affects-7.5 affects-8.1 affects-8.5 severity/moderate sig/sql-infra type/bug type/regression
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

https://github.com/pingcap/tidb/blob/02cd006bd050517337761dc19461a2c0c9edce6e/pkg/ttl/ttlworker/scan.go#L131-L132

This is not handled when session is exited and it is causing other session being killed after recycling the wrong session.

https://github.com/pingcap/tidb/blob/02cd006bd050517337761dc19461a2c0c9edce6e/pkg/ttl/ttlworker/session.go#L97-L121

### 1. Minimal reproduce step (Required)

```
func TestGetSessionBug(t *testing.T) {
store, _ := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)

pool := pools.NewResourcePool(func() (pools.Resource, error) {
return tk.Session(), nil
}, 1, 1, 0)
defer pool.Close()

se, err := ttlworker.GetSessionForTest(pool)
require.NoError(t, err)
rows, err := se.ExecuteSQL(context.Background(), "select sleep(2),@@TIME_ZONE")
require.NoError(t, err)
require.Equal(t, "UTC", rows[0].GetString(1))
se.KillStmt()
, err = se.ExecuteSQL(context.Background(), "select sleep(2),@@TIME_ZONE")
require.NoError(t, err)
fmt.Printf("\n\nxhebox1 %d %d\n", &se.GetSessionVars().SQLKiller.Signal, pool.Available())
se.Close()

se, err = ttlworker.GetSessionForTest(pool)
require.NoError(t, err)
fmt.Printf("\n\nxhebox4 %d %d\n", &se.GetSessionVars().SQLKiller.Signal, pool.Available())
_, err = se.ExecuteSQL(context.Background(), "select @@TIME_ZONE")
require.NoError(t, err)
se.Close()
}
```

Somehow SQL is not killed in my local ENV, but it will cause problem in theory.

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

### 3. What did you see instead (Required)

### 4. What is your TiDB version? (Required)

from v7.1, to https://github.com/pingcap/tidb/commit/2d42a5b32a595d41875cae7d0e894c0fea820182

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.