Repository navigation
Closed
Copy link
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- Hardware parameters: Apple Silicon local environment
- OS type: macOS
- Others: MatrixOne 1 LOG / 1 TN / 2 CN / Proxy; MySQL Connector/J 8.3.0;
useServerPrepStmts=true,useCursorFetch=true
Actual Behavior
When a JDBC client is reading a server-side cursor through Proxy, marking the cursor's CN as Draining causes Proxy to transfer that connection while the cursor still has unread rows. The target CN receives the next COM_STMT_FETCH without an active cursor and returns:
java.sql.SQLException: invalid state prepared statement has no active cursor
at com.mysql.cj.jdbc.result.ResultSetImpl.next(...)
Caused by: com.mysql.cj.exceptions.CJException: invalid state prepared statement has no active cursor
at com.mysql.cj.protocol.a.result.ResultsetRowsCursor.fetchMoreRows(...)
The result stream terminates before all rows are delivered. Proxy logs one completed connection transfer for the affected tunnel.
Expected Behavior
Proxy must not complete a connection transfer while the client has an active server cursor whose remaining cursor state cannot be reconstructed on the target CN. It should either defer the transfer until the cursor is closed/exhausted or migrate the cursor state. The client must receive the complete ordered result without duplicates or truncation.
Steps to Reproduce
- Start MatrixOne with two CNs and Proxy; keep both CNs in
Workingstate. - Create a table with 5,000 rows and connect through Proxy with:
useServerPrepStmts=true&useCursorFetch=true&defaultFetchSize=13
- Ensure the connection is routed to CN2, then execute and begin reading:
PreparedStatement ps = connection.prepareStatement(
"select id,payload from jdbc_streaming_cursor order by id",
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
ps.setFetchSize(13);
ResultSet rs = ps.executeQuery();
rs.next();- While rows remain unread, make CN1
Workingand mark CN2Draining:
select mo_ctl('cn','workstate','<cn1-uuid>:1');
select mo_ctl('cn','workstate','<cn2-uuid>:2');- Continue calling
rs.next()slowly enough for the Proxy scaling interval to run. The fetch fails withprepared statement has no active cursorafter Proxy transfers the tunnel.
Additional information
- With a reading window longer than the five-second Proxy scaling interval, the behavior reproduced 3/3 while alternating the source and target CN.
- Each reproduction recorded one Proxy
transfer endbefore the cursor error. - A shorter timing window reproduced only when transfer happened before result exhaustion (1/3), confirming that the failure is tied to transfer during the active cursor rather than to the query itself.
- Without CN draining/migration, the same cursor configuration returned all 5,000 ordered rows and 5.12 MB of binary payload on CN1, CN2, and Proxy, 3/3 each.
- Ordinary server-side prepared statements with no active cursor survived three CN-draining migration rounds; prepared objects and session variables remained usable. The boundary is specifically the active cursor state.
- Related Java/JDBC release-gate tracking: [TestCase]: Java + MyBatis+MO framework scenario testing #26623.
Activity
fix(proxy): defer migration while prepared cursors are active (#29191)
daviszhen commentedon Sep 28, 2026
Local validation
Validated the issue scenario against the latest
main:9b7c2c23dba737232d975d66bd04628199e1a4366d3d588from PR #29191useServerPrepStmts=true,useCursorFetch=true, fetch size 13Results:
COUNT(*)query and returned 5,000.OkExpectedNotSafeToStartTransferand deferred migration.connection migrate from server,connection migrate to server, andtransfer to a new CN server.pkg/proxyandpkg/frontendtests also passed.Conclusion: the reported
COM_STMT_FETCHfailure was not reproduced on the latestmain; active prepared cursors are now kept on their original CN until the cursor response terminates, and migration is performed afterward.Ariznawlll commentedon Oct 2, 2026
测试版本
maind50a2d475a406829f67127fef7b2ad4abc1c1d3d原问题验证
在上述 commit 运行 issue 对应的定向回归。活动 JDBC cursor 存在时迁移被延后,最终 FETCH terminator 前不会替换后端;已有 2-CN Proxy/JDBC 5000 行 cursor 验证完整。
Happy Path 覆盖
覆盖 cursor 正常 fetch 完成后迁移、普通非 cursor 请求。
Unhappy Path 覆盖
覆盖旧 CN 无 cursor attestation、final packet 边界和迁移竞态;连接不丢行。
白盒验证
关联修复 #29191 已进入当前
main。直接执行并检查的定向测试为:pkg/frontend/routine_test.go::TestMigrateConnectionFromRejectsActivePreparedCursors、pkg/proxy/conn_migration_test.go::TestMigrateConnFromRejectsOldCNWithoutCursorAttestation、pkg/proxy/tunnel_test.go::TestFinalFetchKeepsTransferBlockedUntilTerminator。回归测试
本问题依赖内部故障注入、并发时序、catalog/optimizer 状态或多组件协议边界,无法由普通 SQL golden 稳定构造,因此不放入 MOTR;回归保留在 MatrixOne UT/BVT 层。对应定向测试在精确 commit 上通过,且未修改用户工作区。
测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3dpkg/frontend/routine_test.go::TestMigrateConnectionFromRejectsActivePreparedCursors、pkg/proxy/conn_migration_test.go::TestMigrateConnFromRejectsOldCNWithoutCursorAttestation、pkg/proxy/tunnel_test.go::TestFinalFetchKeepsTransferBlockedUntilTerminator测试结论
测试通过。