Repository navigation
Description
Is there an existing issue for the same bug?
- I searched open and closed issues and fix PRs.
Related but not duplicates:
- [Bug]: DEALLOCATE PREPARE silently succeeds for an unknown statement #25978 / fix(frontend): reject unknown prepared deallocation #26259 cover text-protocol
DEALLOCATE PREPAREfor an unknown name. This report is about binary-protocolCOM_STMT_CLOSE, whose response contract is different. - [Bug]: truncated COM_STMT_CLOSE and COM_STMT_RESET packets enter panic recovery #25744 covers truncated
COM_STMT_CLOSE/COM_STMT_RESETpackets. - [Bug]: Protocol-level prepared statements fail with mysql-connector-python prepared cursor #25423 covers normal binary Prepare execution and is already fixed.
Branch Name
main
Commit ID
71031d0e9e45920821d71ce03f519181d346e669
Other Environment Information
- MatrixOne was built from the commit above.
- MySQL control: 8.0.46.
- JDBC clients: MySQL Connector/J 8.0.33 and 26.7.0.
- The deterministic protocol probe was repeated 3 times per endpoint on fresh connections.
Actual Behavior
MatrixOne sends an error response for COM_STMT_CLOSE when the statement id is absent. The classic MySQL protocol defines COM_STMT_CLOSE as a no-response command, including the absent-id path.
This leaves an unexpected packet in the response stream because clients do not read a response for this command. A following command may consume that packet instead of its own response.
Deterministic two-command probe on a fresh connection:
- Send
COM_STMT_CLOSEwith statement id0. - Send
COM_PINGwithout reading between the two commands. - Read the first response packet.
Results, 3/3:
MatrixOne: first packet = ERR, code 20400
MySQL 8.0.46: first packet = OK for COM_PING
Every fresh MatrixOne connection still prepares and executes SELECT ? successfully, so the effect is isolated to the connection whose packet stream was shifted.
JDBC impact observed with Connector/J 26.7.0:
- A server-side
prepareStatement(...)fails, for example because the SQL references an absent object. - Connector/J cleans up its half-constructed server statement with
COM_STMT_CLOSEand does not expect a response. - A following ordinary or prepared statement can intermittently receive
HY000 / 20400, reporting that internal prepared statement__mo_stmt_id_0does not exist. - Connector/J 8.0.33 did not take the same cleanup path in this matrix; MySQL remained synchronized with both versions.
Expected Behavior
COM_STMT_CLOSE must not send a response packet. An absent statement id should be handled silently on this binary command, while text SQL DEALLOCATE PREPARE unknown_name may continue returning MySQL error 1243.
MySQL's protocol source documents:
COM_STMT_CLOSEdeallocates a prepared statement. No response packet is sent back to the client. Return: None.
The MySQL server's absent-id branch for COM_STMT_CLOSE also goes to silent_error.
Primary references:
- https://github.com/mysql/mysql-server/blob/trunk/sql/protocol_classic.cc (
page_protocol_com_stmt_close) - https://github.com/mysql/mysql-server/blob/trunk/sql/sql_prepare.cc (
mysql_stmt_precheck,COM_STMT_CLOSE)
Root Cause
In pkg/frontend/mysql_cmd_executor.go, the COM_STMT_CLOSE branch calls Session.GetPrepareStmt. When the id is absent it returns a GeneralErrorResponse. The frontend then writes that error packet even though this protocol command must not produce any response.
The existing unit expectation for a missing binary close also treats an error response as correct, so the protocol mismatch is currently encoded in the test.
Recovery and Consistency Checks
- Reproduced on the latest official
maincommit above. - MatrixOne result was identical in 3/3 deterministic runs.
- MySQL control was identical in 3/3 runs and did not emit a close response.
- A fresh connection remained usable after every run.
- The probe performs no table writes, so there is no partial-data outcome.
Activity
Ariznawlll commentedon Aug 19, 2026
Latest-main recheck after
mainadvanced:493ab8a9585576b76508d054fef58ccb55c206c5LAST_QUERY_ID; the frontend protocol path is unchanged.COM_STMT_CLOSE(id=0) -> COM_PINGprobe: MatrixOne returned the extraERR/20400packet in 3/3 runs.COM_PINGOK packet in 3/3 runs.The issue remains reproducible on the exact current
origin/main.XuPeng-SH commentedon Oct 15, 2026
Reconfirmed on 2026-10-15 through an ordinary Python DB-API error/reuse path (no hand-built packets), on both:
1a44f3db3056e32975fde86ca0ab69a094996a3f, executable SHA2565d136df6fab5e7a5bdf4ba3e678470d898c8d681f3fdae99095ecd9c4205d2ed.14686eb61cc510ff456951b946e8e33496806320, executable SHA256a9fe1d1f71eed4c714d28abfde2e19bdf5ff8be2877b0e65bc5d154205c5eed2. Closing main-tip check still matched this SHA. Production source unchanged.mysql-connector-python==26.7.0,use_pure=True, independent task-owned local services.Minimal normal-client sequence on a fresh connection:
This reproduced 3/3 fresh connections per version. A following
SELECT 55 AS text_afterreturned an empty result instead of55 in all affected trials, consistent with a shifted response stream; this is not an independent SQL-result/ACL defect. Valid reprepare controls and replacing the failed prepared cursor with a new cursor both returned the expected scalar values3/3 per version. Release returns strings for the bare prepared parameter whereas main returns integers; these raw metadata/type observations were retained and not conflated with the synchronization error.Tracing only the connector's public connection-method calls shows its failed-PREPARE path retains the old, already-closed statement handle; subsequent reuse calls
cmd_stmt_closefor that old id before the next prepare. In this main source, the absent-handle close branch still returnsNewGeneralErrorResponse, and the routine writes non-nil responses. This is the existing no-response contract defect tracked here, now reached by ordinary cursor error handling. No explicit duplicate-close command was sent by the test program.This path initially contaminated a shared query/EXPLAIN sampling connection during hybrid fulltext/vector testing. With plan sampling isolated on its own connections, the main180s write/read/live-IVF-rebuild profile and independent restart audits passed. The contaminated downstream assertions are not being filed as separate ACL or ANN bugs. These SELECT-only cursor probes do not establish a service crash, data loss, or the cause of any restart-recovery incident.
XuPeng-SH commentedon Oct 15, 2026
@jiangxinmeng1
fix(frontend): silence missing binary statement closes (#31413)
XuPeng-SH commentedon Oct 28, 2026
QA status for merged main
f97056d1107a89854bfac2c06202698e3aafd41e(#31413): no current-head frontend or binary-protocol test has been run in this environment. Available memory/disk headroom under the existing guard is insufficient for a safe frontend link or current-head service. The original missing/known/repeated COM_STMT_CLOSE followed by PING and ordinary prepared-cursor error/reuse path remain pending independent verification; no product failure is inferred from the resource limitation. Handing off to QA for verification.Ariznawlll commentedon Oct 28, 2026
结论
测试通过。二进制协议对不存在、正常和重复关闭的语句均不发送响应,后续命令保持对齐。
关键证据
main@72d99c85751dc5b9b7775cb50571e7efd6400487,包含已合入修复 PR fix(frontend): silence missing binary statement closes #31413;macOS arm64 隔离单进程 LogService / TN / CN,实际启动二进制git_version()为72d99c8575。COM_STMT_CLOSE(id=0)后立即发送COM_PING,首个响应均为 PING 的 OK,3/3;准备有效语句后关闭及再次关闭,再发送 PING 均为 OK,3/3。文本协议DEALLOCATE PREPARE不存在的名称仍返回 1243,随后SELECT 42正常。SELEC ?,复用原游标执行参数查询得到 44,普通查询前后分别得到 33 和 55,3/3。Connector/J 26.7.0 和 8.0.33 的真实服务端预编译失败后在同一连接继续预编译查询,也分别 3/3。9e29011e7313a57962adc00963baa659d1e81e37,重建对应二进制后,MOTR 协议场景在新 SHA 补跑 3/3,通过且 0 跳过;此前 JDBC / Python 客户端各 3/3 结果仍对应72d99c…。待解决点
无。