Repository navigation
Description
Environment
- matrixorigin/matrixone, commit 26e3289 (detached HEAD of main, 26e3289dd61a68fe8ba059cf2862ad2ca5e40)
- macOS 15.7, Apple Silicon (arm64)
- Single-node
mo-servicebuilt in this workspace, launched with.loom-test/launch/launch.toml(copy ofetc/launchwith all ports offset by LOOM_TEST_PORT_OFFSET=20000; MySQL protocol port 26201), data dir.loom-test/mo-data - Client:
mysqlCLI, account dump/111,--local-infile=1(required), databaseen21 - 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; tableki (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:
- Whole victim connection destroyed (6/11): the killer's
KILL QUERY <cid>returns OK (rc=0), then the victim client dies withERROR 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). - Silent no-op with committed data (3/11):
KILL QUERYreturns OK, the victim finishes normally with no error whatsoever, and all 4,000,000 rows are committed (count=4000000). - Unknown connection id while load continues (2/11):
KILL QUERYfails withERROR 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):
KILL QUERY <cid>returns OK to the killer session (no error);- the in-flight
LOAD DATA LOCALaborts withERROR 1317 (70100) at line 1: Query execution was interrupted, delivered to the victim over the same connection; - the victim session stays alive (documented: KILL QUERY terminates only the statement, the connection remains usable - https://dev.mysql.com/doc/refman/8.0/en/kill.html);
- rows received so far are rolled back (
select count(*)-> 0).
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 callsrt.killQuery(...).pkg/frontend/routine.go:600-610:killQuerymerely cancels the per-request context (cancelRequestCtx, created per request atpkg/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 fromexecCtx.reqCtx).pkg/frontend/mysql_cmd_executor.go:5386-5395:processLoadLocal's cancellation watcher treatsctx.Done()as a fatal protocol event and callsmysqlRwer.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 throughkill.go:73-75-> routine not found locally ->killSessionfallback atkill.go:136reportsUnknown 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.goare unchanged betweenb466f4ae9b(the commit referenced by [Bug]: KILL QUERY fails with "Unknown connection id" on a connection running LOAD DATA LOCAL #31278) and HEAD26e3289dd6, 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
- Preserve the
KILL QUERYunknown-connection-ID reproduction and ordinarySLEEPcontrol from [Bug]: KILL QUERY fails with "Unknown connection id" on a connection running LOAD DATA LOCAL #31278 alongside the existing disconnect, no-op and retry/timing scenarios. - Independently test
KILL <id>(connection form): it must resolve the correct connection and follow connection-kill semantics, including rollback;KILL QUERYmust retain its separate statement/session contract.
Original reproduction remains at #31278. Consolidation does not mean the problem is fixed.
Activity
fix(frontend): preserve LOCAL upload framing on KILL QUERY (#31703)
Ariznawlll commentedon Oct 30, 2026
结论
测试通过。
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。context canceled、连接 ID 不变并可继续查询,目标表均为 0 行。文件与独立测试库已清理。文件由等行数、等字节数的合成记录构造,不是原始文件的逐字节副本。TestKillLoadLocal真正启动 SQL 集群,覆盖分片包、结束前、显式事务、KILL CONNECTION、完成及 SLEEP 对照等路径,重复 10 次通过;TestProcessLoadLocalResumesInterruptedFrame普通和-race各 10 次通过。测试使用与当前原生源码一致、已核对来源的本地 CGo 依赖。待解决点
iamlinjunhong commentedon Nov 20, 2026
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_payloadexpected MySQL error 1317 afterKILL QUERY. The runner loggedcontext canceledfrom the upload goroutine, then returned error 1105 withio: 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
mainb543648d99395492918ce0a5a3c08a7de952042d. Both local builds used their exact source inputs via overlays on Darwin/arm64, with CGO,-short -tags matrixone_test -covermode=set -coverpkg=./pkg/sql/crtand 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/sqlintegrationwith 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.fix(frontend): preserve cancellation errors during LOCAL uploads (#33053
Share JSON parsing in projections and preserve statistics on cancella…