Skip to content

TiDB server panic when executing kill query on an idle transaction #63956

@pcqz7

Description

@pcqz7

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Session 1

mysql> create table t(id int);
Query OK, 0 rows affected (0.07 sec)

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values(1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into t select * from t;
Query OK, 1 row affected (0.00 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> insert into t select * from t;
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> insert into t select * from t;
Query OK, 4 rows affected (0.00 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> insert into t select * from t;
Query OK, 8 rows affected (0.00 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> insert into t select * from t;
Query OK, 16 rows affected (0.01 sec)
Records: 16  Duplicates: 0  Warnings: 0

mysql> insert into t select * from t;
Query OK, 32 rows affected (0.01 sec)
Records: 32  Duplicates: 0  Warnings: 0

Session 2

mysql> show processlist;
+------------+------+----------------+------+---------+------+----------------------------+------------------+
| Id         | User | Host           | db   | Command | Time | State                      | Info             |
+------------+------+----------------+------+---------+------+----------------------------+------------------+
| 2480930824 | root | 10.2.8.3:61605 | NULL | Query   |    0 | autocommit                 | show processlist |
| 2480930830 | root | 10.2.8.3:14490 | test | Sleep   |    6 | in transaction; autocommit | NULL             |
+------------+------+----------------+------+---------+------+----------------------------+------------------+
2 rows in set (0.00 sec)

mysql> kill query 2480930830;
Query OK, 0 rows affected (0.00 sec)

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

Nothing happens.

3. What did you see instead (Required)

TiDB server panic

panic: [executor:1317]Query execution was interrupted

goroutine 6292 [running]:
github.com/pingcap/tidb/pkg/util/memory.(*Tracker).Consume(0xc003a6f298?, 0x4000)
        /workspace/source/tidb/pkg/util/memory/tracker.go:507 +0x285
github.com/pingcap/tidb/pkg/util/memory.(*Tracker).ReplaceBytesUsed(...)
        /workspace/source/tidb/pkg/util/memory/tracker.go:793
github.com/pingcap/tidb/pkg/session.(*session).SetMemoryFootprintChangeHook.func1(0x1?)
        /workspace/source/tidb/pkg/session/session.go:4333 +0xc9
github.com/tikv/client-go/v2/internal/unionstore/art.(*ART).SetMemoryFootprintChangeHook.func1()
        /root/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.8-0.20250417032542-dfc632806f5f/internal/unionstore/art/art.go:580 +0x23
github.com/tikv/client-go/v2/internal/unionstore/arena.(*MemdbArena).OnMemChange(0x50?)
        /root/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.8-0.20250417032542-dfc632806f5f/internal/unionstore/arena/arena.go:162 +0x1c
github.com/tikv/client-go/v2/internal/unionstore/art.(*ART).Cleanup(0xc233a10b764d1f77?, 0x67278d1?)
        /root/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.8-0.20250417032542-dfc632806f5f/internal/unionstore/art/art.go:528 +0xf1
github.com/tikv/client-go/v2/internal/unionstore.(*artDBWithContext).Cleanup(0xc00af80a50?, 0x1?)
        /root/go/pkg/mod/github.com/tikv/client-go/v2@v2.0.8-0.20250417032542-dfc632806f5f/internal/unionstore/memdb_art.go:94 +0x6f
github.com/pingcap/tidb/pkg/store/driver/txn.(*memBuffer).Cleanup(0x653d740?, 0xc001924d00?)
        /workspace/source/tidb/pkg/store/driver/txn/unionstore_driver.go:75 +0x1b
github.com/pingcap/tidb/pkg/session.(*LazyTxn).cleanupStmtBuf(0xc0042d7b10)
        /workspace/source/tidb/pkg/session/txn.go:152 +0x83
github.com/pingcap/tidb/pkg/session.(*LazyTxn).cleanup(0xc0042d7b10)
        /workspace/source/tidb/pkg/session/txn.go:563 +0x18
github.com/pingcap/tidb/pkg/session.(*LazyTxn).reset(0xc0042d7b10)
        /workspace/source/tidb/pkg/session/txn.go:558 +0x18
github.com/pingcap/tidb/pkg/session.(*LazyTxn).Rollback(0xc0042d7b10)
        /workspace/source/tidb/pkg/session/txn.go:445 +0xa3
github.com/pingcap/tidb/pkg/session.(*session).RollbackTxn(0xc0042d7b08, {0x706ba28?, 0xc00860d0e0?})
        /workspace/source/tidb/pkg/session/session.go:945 +0xc5
github.com/pingcap/tidb/pkg/session.(*session).Close(0xc0042d7b08)
        /workspace/source/tidb/pkg/session/session.go:2563 +0x3df
github.com/pingcap/tidb/pkg/server.(*TiDBContext).Close(0xc004827cf8)
        /workspace/source/tidb/pkg/server/driver_tidb.go:310 +0xb1
github.com/pingcap/tidb/pkg/server.closeConn.func1()
        /workspace/source/tidb/pkg/server/conn.go:409 +0x265
sync.(*Once).doSlow(0xc0080fbcf8?, 0x8?)
        /usr/local/go/src/sync/once.go:76 +0xb4
sync.(*Once).Do(...)
        /usr/local/go/src/sync/once.go:67
github.com/pingcap/tidb/pkg/server.closeConn(0xc003db0448?)
        /workspace/source/tidb/pkg/server/conn.go:388 +0x4b
github.com/pingcap/tidb/pkg/server.(*clientConn).Close(0xc0085b0000)
        /workspace/source/tidb/pkg/server/conn.go:381 +0x65
github.com/pingcap/tidb/pkg/server.(*clientConn).Run.func1()
        /workspace/source/tidb/pkg/server/conn.go:1051 +0x3fa
github.com/pingcap/tidb/pkg/server.(*clientConn).Run(0xc0085b0000, {0x706ba28, 0xc0085ba990})
        /workspace/source/tidb/pkg/server/conn.go:1127 +0x1691
github.com/pingcap/tidb/pkg/server.(*Server).onConn(0xc003db0400, 0xc0085b0000)
        /workspace/source/tidb/pkg/server/server.go:741 +0x81f
created by github.com/pingcap/tidb/pkg/server.(*Server).startNetworkListener in goroutine 4248
        /workspace/source/tidb/pkg/server/server.go:560 +0x674

4. What is your TiDB version? (Required)

v8.5.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-8.5This bug affects the 8.5.x(LTS) versions.report/customerCustomers have encountered this bug.severity/majorsig/executionSIG executiontype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions