Skip to content

[Bug]: KILL QUERY during in-flight LOAD DATA LOCAL severs the connection, no-ops, or returns Unknown connection id #31475

Closed

Description

@iamlinjunhong

Environment

  • matrixorigin/matrixone, commit 26e3289 (detached HEAD of main, 26e3289dd61a68fe8ba059cf2862ad2ca5e40)
  • macOS 15.7, Apple Silicon (arm64)
  • Single-node mo-service built in this workspace, launched with .loom-test/launch/launch.toml (copy of etc/launch with all ports offset by LOOM_TEST_PORT_OFFSET=20000; MySQL protocol port 26201), data dir .loom-test/mo-data
  • Client: mysql CLI, account dump/111, --local-infile=1 (required), database en21
  • Load: LOAD DATA LOCAL INFILE '<150MB csv>' INTO TABLE ki FIELDS TERMINATED BY ',' (x, s) - a 150,888,896-byte CSV with 4,000,000 rows; table ki (id bigint auto_increment primary key, x int, s varchar(40)). The LOCAL upload phase makes the load long enough (several seconds) to hit it with KILL QUERY mid-flight.
  • MySQL comparison: local MySQL 8.0.46 (mysqld --initialize-insecure, port offset applied, --local-infile=1, same machine, same client, same CSV)

Actual Behavior

KILL QUERY issued against a session that is executing LOAD DATA LOCAL never aborts just the statement. Across 11 attempts (each verified via timestamped SHOW PROCESSLIST polling that the LOAD was still running at kill time), three outcomes occurred, none of them the documented one:

  1. Whole victim connection destroyed (6/11): the killer's KILL QUERY <cid> returns OK (rc=0), then the victim client dies with ERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query; the victim session disappears; rows received so far are rolled back (count=0). Observed for kills issued 0-2s into the load (LOCAL upload phase).
  2. Silent no-op with committed data (3/11): KILL QUERY returns OK, the victim finishes normally with no error whatsoever, and all 4,000,000 rows are committed (count=4000000).
  3. Unknown connection id while load continues (2/11): KILL QUERY fails with ERROR 20101 (HY000): internal error: Unknown connection id <cid> while the load keeps running and commits 4,000,000 rows; the victim session survives intact (same connection_id). Observed for kills issued ~5s into the load. This variant matches open issue [Bug]: KILL QUERY fails with "Unknown connection id" on a connection running LOAD DATA LOCAL #31278.

0 out of 11 runs produced the documented statement-level interruption.

Control experiment: KILL QUERY against select sleep(8) on the same server interrupts the statement normally - the victim gets ERROR 1317 (70100) at line 1: context canceled and the client connection survives - so the query-level interrupt machinery works for ordinary statements; only the LOAD DATA LOCAL lifecycle is mishandled.

This matters operationally: kill query is the standard way to stop a runaway import without losing the session (it is what SHOW PROCESSLIST tells you to do, and what MySQL tools do). In MatrixOne the same command randomly kills the whole client connection, does nothing while the data lands anyway, or refuses with an internal error - three different, all-wrong results for one input.

Expected Behavior

MySQL 8.0 semantics (verified 3/3 on local MySQL 8.0.46 with the identical script and CSV, kill issued mid-upload):

MatrixOne must pick this single outcome for every timing, instead of the current three-way random split.

Steps to Reproduce

Self-contained script (also in repro): prepare the 4M-row CSV, start one victim LOAD DATA LOCAL per round, poll show processlist to catch its numeric connection id, issue kill query <cid> after 0/2/5 seconds, then report the victim's fate and the surviving row count. Run the outer loop a few times to observe different outcomes.

Note: in MatrixOne the column list must come after the FIELDS TERMINATED BY ',' clause (different from MySQL, which accepts both orders) - the script uses the MatrixOne order.

Additional information

Root cause analysis - the frontend has no statement-scoped interrupt for the LOCAL-load lifecycle, so KILL QUERY degenerates into request/connection-level operations:

  • pkg/frontend/kill.go:92-95: for KILL QUERY the frontend only calls rt.killQuery(...).
  • pkg/frontend/routine.go:600-610: killQuery merely cancels the per-request context (cancelRequestCtx, created per request at pkg/frontend/routine.go:299) and clears the executing flag. The LOAD DATA LOCAL upload pump runs on this request context (pkg/frontend/authenticate.go:11798: Upload() derives the upload ctx from execCtx.reqCtx).
  • pkg/frontend/mysql_cmd_executor.go:5386-5395: processLoadLocal's cancellation watcher treats ctx.Done() as a fatal protocol event and calls mysqlRwer.Disconnect() (line 5392), retiring the entire client connection - its own comment (5364-5367) says the upload "either reaches the protocol EOF or retires its connection". That is outcome 1: the victim loses the TCP connection instead of receiving ERROR 1317. Because the LOCAL upload is half of a MySQL client command, breaking the connection here also discards anything else the client batch still wanted to run.
  • Outcome 3 (Unknown connection id) goes through kill.go:73-75 -> routine not found locally -> killSession fallback at kill.go:136 reports Unknown connection id %d; i.e. the same path as issue [Bug]: KILL QUERY fails with "Unknown connection id" on a connection running LOAD DATA LOCAL #31278. routine_manager.go / kill.go / routine.go are unchanged between b466f4ae9b (the commit referenced by [Bug]: KILL QUERY fails with "Unknown connection id" on a connection running LOAD DATA LOCAL #31278) and HEAD 26e3289dd6, yet in this environment [Bug]: KILL QUERY fails with "Unknown connection id" on a connection running LOAD DATA LOCAL #31278's 100%-deterministic 20101 outcome only occurs in 2/11 runs and is dominated by two other broken behaviors.
  • Outcome 2 (silent no-op, load commits) was observed reproducibly at several delays, but the precise code branch for it was not pinned down; what is certain is that no ERROR 1317 is ever delivered and nothing is rolled back. It resembles the symptom of closed issue [Bug]: kill load data statement , data can be found, not rollback #7442 (v0.7.0-era, server-side infile kill without rollback), so this failure mode may have been intended to be fixed by that work.

Recommendation: give the LOCAL upload a statement-scoped interrupt path - on KILL QUERY, abort the import statement, send ERROR 1317 to the victim, keep the TCP connection by draining/discarding the remaining LOCAL packets until the client's EOF marker so the command boundary is preserved, and roll back; additionally keep the routine resolvable for the whole load lifecycle (that alone would remove outcome 3 / #31278).

Relationship to existing issues: #31278 (open, s1, same LOAD DATA statement) describes only outcome 3 and claims 100% determinism; the two dominant outcomes here (whole-connection severing at 2013; silent no-op with fully committed import) are not described there, and fixing only the routine lookup would not make KILL QUERY behave as documented, so this is reported separately rather than as a duplicate. #7442 (closed COMPLETED 2023-02, v0.7.0) was "kill load data statement, data can be found, not rollback" for server-side infile - same failure shape as outcome 2 but a different path, and closed. Also checked, different scenarios: #26067 (closed; KILL not cancelling a specific query shape), #29693 (closed; multi-CN KILL returning 1105), #30387 (client disconnect leaving statements running - inverse direction), #31308 (cancel reporting EOF to workers).

Full reproduction, exactly as Loom ran it
#!/bin/bash
# KILL QUERY against an in-flight LOAD DATA LOCAL on MatrixOne.
# Prereq: single-node mo-service on 127.0.0.1:26201 (account dump/111, db en21), mysql client in PATH.
# Run the whole script several times: the outcome varies per run (connection lost / silent no-op / ERROR 20101).
M() { MYSQL_PWD=111 mysql -h 127.0.0.1 -P 26201 -u dump --local-infile=1 -D en21 "$@"; }
CSV=$TMPDIR/ai.csv
awk 'BEGIN{for(i=1;i<=4000000;i++)print i",str-"i}' >"$CSV"    # ~151MB, 4M rows
for DELAY in 0 2 5; do
  M -e "drop table if exists ki; create table ki (id bigint auto_increment primary key, x int, s varchar(40))"
  POLL=$(mktemp); : >"$POLL"
  ( while :; do M -N -e "show processlist" 2>/dev/null | awk '$2~/^[0-9]+$/ && substr($0,1,400) ~ /into table ki / {print $2}' >>"$POLL"; sleep 0.2; done ) & POLLER=$!
  VOUT=$(mktemp)
  ( M --force -e "load data local infile '$CSV' into table ki fields terminated by ',' (x,s); select connection_id() as cid_after,'ALIVE'; select count(*) as cnt from ki" >"$VOUT" 2>&1 ) & VICT=$!
  CID=; for t in $(seq 40); do CID=$(tail -1 "$POLL"); [ -n "$CID" ] && break; sleep 0.2; done
  sleep "$DELAY"
  echo "== RUN delay=${DELAY}s: kill query $CID"
  M -e "kill query $CID"; echo "kill_rc=$?"
  wait $VICT; kill $POLLER 2>/dev/null
  echo "-- victim output:"; cat "$VOUT"
  echo "-- rows left in ki: $(M -N -e 'select count(*) from ki')"
done
# Actual (MatrixOne @ 26e3289dd6) - one of three, never the documented one:
#   ERROR 2013 (HY000) at line 1: Lost connection to MySQL server during query  -> victim session dead, rows left 0
#   or no error at all in victim output, rows left 4000000 (kill silently ineffective)
#   or killer gets: ERROR 20101 (HY000) at line 1: internal error: Unknown connection id <cid>, rows left 4000000
# Expected (verified on local MySQL 8.0.46 with same script/CSV): killer rc=0, victim reports
#   ERROR 1317 (70100) at line 1: Query execution was interrupted, victim session alive, rows left 0.

Found by Loom bug hunt (module: custom-82082add71; tests: white-box, black-box, concurrency; severity: S1)

Additional connection-form coverage from #31278

Original reproduction remains at #31278. Consolidation does not mean the problem is fixed.

Activity

  1. added
    kind/bug
    severity/s1
    on Oct 27, 2026
  2. added a commit that references this issue on Oct 29, 2026
    1ce112f
  3. added
    ai-easy
    on Oct 29, 2026
  4. Ariznawlll commented on Oct 30, 2026

    @Ariznawlll
    Collaborator

    结论

    测试通过。KILL QUERY 可中断进行中的 LOCAL 导入并回滚,客户端连接保持可用;合并进本 issue 的 KILL 连接形式也通过定向集成覆盖。

    关键证据

    • 执行时官方 main@a54850983d9cddaacc97e38a84515ec724c937b7;修复 PR fix(frontend): preserve LOCAL upload framing on KILL QUERY #31703 的合并提交 1ce112f0142021db80f62f101bc9e9580ed8ef90 在祖先链。隔离 macOS arm64、1 CN / 1 TN / 1 LogService;运行二进制构建元数据及 git_version() 对应该 SHA。
    • 使用 400 万行、150,888,896 字节 CSV,在进程列表确认 LOAD 正在执行后,按 0、2、5 秒轮换取消,10/10 次 KILL 成功,导入端均返回 1317 context canceled、连接 ID 不变并可继续查询,目标表均为 0 行。文件与独立测试库已清理。文件由等行数、等字节数的合成记录构造,不是原始文件的逐字节副本。
    • 当前源码的 TestKillLoadLocal 真正启动 SQL 集群,覆盖分片包、结束前、显式事务、KILL CONNECTION、完成及 SLEEP 对照等路径,重复 10 次通过;TestProcessLoadLocalResumesInterruptedFrame 普通和 -race 各 10 次通过。测试使用与当前原生源码一致、已核对来源的本地 CGo 依赖。
    • 该问题已有 #31703 内部帧恢复及 SQL 集成回归,已实际执行;本次未把缩小文件规模的普通 SQL 用例当作原规模验证,也未新增重复 MOTR 用例。

    待解决点

    • 本次未运行完整 MatrixOne CI 或多 CN/Proxy 路由;单 CN 结果不外推多 CN。4M 文件是构造数据,未覆盖报告外的网络分区或异常断流。
  5. iamlinjunhong commented on Nov 20, 2026

    @iamlinjunhong
    ContributorAuthor

    Intermittent LOCAL upload cancellation error in coverage CI

    PR #32980 at a22e3cbe171701a4214c2480f6368d5e95045d97. The coverage workflow run 44686384841, attempt 1, failed in the Ubuntu/x64 coverage job 136121863962.

    pkg/tests/sqlintegration.TestKillLoadLocal/partial_payload expected MySQL error 1317 after KILL QUERY. The runner logged context canceled from the upload goroutine, then returned error 1105 with io: read/write on closed pipe. This occurred during test execution. The ordinary UT job executed the same package without reporting this failure.

    The exact subtest passed 3/3 on the original PR head and 3/3 on official main b543648d99395492918ce0a5a3c08a7de952042d. Both local builds used their exact source inputs via overlays on Darwin/arm64, with CGO, -short -tags matrixone_test -covermode=set -coverpkg=./pkg/sql/crt and no race detector. This reproduces the test and its mode with focused instrumentation. The original Linux job instruments the full coverage selection.

    The upload watcher, pipe reader, LOCAL LOAD test and wire error mapping are unchanged. The failed SQL does not use JSON extraction, and the PR's execution statistics are captured after the runner chooses its terminal error. In both revisions the watcher can close the reader during cancellation, while an executor reading that pipe can encounter the closed-pipe sentinel. That path is consistent with the failure log. The three-run controls did not reproduce the error, so this observation remains a flaky candidate under the same LOCAL upload interruption contract tracked here.

    To exercise the case, use go test -short -tags matrixone_test -covermode=set -coverpkg=./pkg/sql/crt -count=3 -run '^TestKillLoadLocal$/^partial_payload$' ./pkg/tests/sqlintegration with the repository's native CGo flags. The repair for the separate SCA and SQL regressions detected in this run will trigger fresh CI on the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s1

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions