Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: go-sql-driver context cancel tidb不生效

Hello everyone~
TiDB version: v5.x
Problem description:
When I use go-sql-driver to access TiDB, the corresponding session in TiDB cannot be canceled after the context ends, but this issue does not occur with MySQL.
The code is as follows:
# 10s timeout
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
# Execute query
rows, err := db.QueryContext(ctx,"select sleep(600)")
After 10 seconds, the timeout is triggered, and the code returns as expected, as follows:
context deadline exceeded
However, when logging into TiDB at this time, I find that the query has not ended in TiDB.
Could you please help me see how to solve this? I don’t want to kill it every time. Or is there any parameter that can be passed?