Skip to content

[Bug]: Connector/J ConnectionPoolDataSource cannot borrow connections because reset commands are unsupported #27644

Closed

Description

@Ariznawlll

Description

MatrixOne declares MySQL protocol commands COM_RESET_CONNECTION (0x1f) and COM_CHANGE_USER (0x11) but does not execute either command. As a result, Connector/J's standard MysqlConnectionPoolDataSource creates the physical connection but cannot return even the first logical pooled connection.

Environment

  • Branch: main
  • Commit: 1891117aedce0419a81630b3011906b560b93d0a
  • Deployment: local single-node launch (etc/launch/launch.toml)
  • OS: macOS arm64
  • Drivers: MySQL Connector/J 8.0.15, 8.4.0, and 9.7.0

Steps to reproduce

MysqlConnectionPoolDataSource ds = new MysqlConnectionPoolDataSource();
ds.setURL("jdbc:mysql://127.0.0.1:6001/test");
ds.setUser(user);
ds.setPassword(password);

PooledConnection pooled = ds.getPooledConnection(); // physical connection succeeds
Connection logical = pooled.getConnection();         // fails during server-state reset

Connector/J calls JdbcConnection.resetServerState() before exposing a logical connection. Modern versions send COM_RESET_CONNECTION; Connector/J 8.0.15 resets through COM_CHANGE_USER.

Actual behavior

Connector/J 8.4.0 and 9.7.0:

java.sql.SQLException: internal error: unsupported command. 0x1f
    at com.mysql.cj.jdbc.ConnectionImpl.resetServerState(...)
    at com.mysql.cj.jdbc.MysqlPooledConnection.getConnection(...)

Connector/J 8.0.15:

java.sql.SQLException: internal error: unsupported command. 0x11
    at com.mysql.cj.jdbc.ConnectionImpl.changeUser(...)
    at com.mysql.cj.jdbc.ConnectionImpl.resetServerState(...)
    at com.mysql.cj.jdbc.MysqlPooledConnection.getConnection(...)

No logical connection can be borrowed from this standard JDBC pool interface.

Expected behavior

MysqlConnectionPoolDataSource.getPooledConnection().getConnection() should succeed. Resetting a pooled session should preserve the authenticated physical connection while restoring clean session state, including rolling back an active transaction, clearing user variables, dropping temporary tables, releasing prepared statements/cursors, and restoring session defaults according to MySQL protocol semantics.

Stability and controls

  • Reproducer: 3/3 with Connector/J 8.4.0 (0x1f).
  • Cross-version: reproduced with Connector/J 8.0.15 (0x11) and 9.7.0 (0x1f).
  • Direct JDBC control: ordinary DriverManager connections and connection_id() queries pass.
  • HikariCP 5.1 control: 10 assertions pass, covering physical connection reuse, rollback on logical close, autocommit restoration, isValid(), and replacement after Connection.abort().
  • No panic, hang, data corruption, or CN restart was observed.

Code analysis

pkg/frontend/mysql_protocol_predefines.go declares both commands. However, ExecRequest in pkg/frontend/mysql_cmd_executor.go has no COM_RESET_CONNECTION or COM_CHANGE_USER branch, so both fall into the default unsupported command response.

Regression coverage

After the fix, add a JDBC/motr test using MysqlConnectionPoolDataSource that verifies first and repeated logical borrows, stable physical connection ID, active-transaction rollback, user-variable cleanup, temporary-table cleanup, prepared-statement cleanup, and clean reuse after a reset error. This is protocol/session coverage and does not require big-data testing.

Activity

  1. added this to the MO-202608 milestone on Aug 26, 2026
  2. added
    kind/bug
    on Aug 26, 2026
  3. added theissue type on Aug 26, 2026
  4. added
    severity/s0
    and removed on Aug 26, 2026
  5. iamlinjunhong commented on Aug 26, 2026

    @iamlinjunhong
    Contributor

    Additional MatrixOne ODBC / unixODBC evidence confirms the same protocol gap affects ODBC connection-pool hygiene, not only Connector/J.

    Environment:

    • MatrixOne 1891117aedce0419a81630b3011906b560b93d0a
    • MatrixOne ODBC candidate 390f3cc58ebc06d5e830a7839cccbca2962ffcc4
    • unixODBC 2.3.12, pyodbc 5.1.0, Ubuntu 24.04.4 LTS x86_64

    ODBC reproduction:

    1. Open two pooled logical connections and create the same-named temporary table with different contents on each physical connection.
    2. Close both logical connections.
    3. Open a third matching logical connection.
    4. Query the temporary table.

    With pyodbc/unixODBC pooling enabled, the third logical connection reuses a physical connection and can still read the prior borrower's temporary table. With pyodbc.pooling = False, the same 12-scenario run cleans the temporary table correctly and improves from 8/12 to 10/12; the remaining two failures are unrelated known compatibility differences.

    Native libmysqlclient controls against this MatrixOne commit confirm both reset paths required by the upstream MySQL ODBC pooling implementation are rejected:

    mysql_change_user failed: 20101 internal error: unsupported command. 0x11
    mysql_reset_connection failed: 20101 internal error: unsupported command. 0x1f
    

    The upstream MySQL ODBC reset path marks a pooled connection for wake-up and calls mysql_change_user() before reuse. Therefore MatrixOne currently cannot provide the server-side session reset needed to drop temporary tables, clear variables and restore defaults on pooled reuse.

    Evidence:

    • artifacts/production-release-20260826/server-rounds-latest/results/server-scenarios-round3.json (R302)
    • artifacts/production-release-20260826/server-rounds-no-pool/results/server-scenarios-round3.json (R302 control)
    • artifacts/production-release-20260826/logs/mysql-change-user-temp-repro-1891117.log
    • artifacts/production-release-20260826/logs/mysql-reset-connection-temp-repro-1891117.log

    Temporary workaround: disable pyodbc/unixODBC pooling for workloads that use session-scoped state (temporary tables, user variables, session options), and explicitly roll back before close.

  6. iamlinjunhong commented on Aug 26, 2026

    @iamlinjunhong
    Contributor

    ODBC/unixODBC confirmation on the latest tested MatrixOne main:

    • MatrixOne: a53f5a3b757c5b21a36e539e4471533fe1d091a8
    • MatrixOne ODBC candidate: 390f3cc58ebc06d5e830a7839cccbca2962ffcc4
    • unixODBC 2.3.12, pyodbc 5.1.0, Linux x86_64

    Native libmysqlclient controls still fail:

    mysql_change_user failed: 20101 internal error: unsupported command. 0x11
    mysql_reset_connection failed: 20101 internal error: unsupported command. 0x1f
    

    With Driver Manager pooling enabled, a temporary table created during one logical pyodbc connection remains present when the same physical connection is borrowed again, so the second CREATE TEMPORARY TABLE unexpectedly succeeds as a lookup but fails the isolation assertion. The same scenario passes when pooling is disabled. A later concurrent DDL case can also observe a stale session/causal state and report 42S02 for a table just created by another logical connection.

    Temporary workaround remains: disable Driver Manager pooling for workloads that depend on clean session state, and explicitly roll back before returning a connection.

  7. added
    ai-easy
    on Sep 8, 2026
  8. Ariznawlll commented on Sep 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:4b43f8c99bb22e6a35c389c93bf64c2dc043feaf
    • 部署方式:本地单 CN / TN / LogService,真实 MySQL wire protocol。
    • 测试日期:2026-09-08

    原问题验证

    同一物理连接创建临时表、设置用户变量并开启未提交事务后发送 COM_RESET_CONNECTION。3 轮均保持 connection id 和当前 database,变量清空、临时表不可见、未提交写入回滚。

    Happy Path 覆盖

    1. COM_RESET_CONNECTION 返回 OK,并保留已认证物理连接和选中 database。
    2. 两次 COM_CHANGE_USER 均完成 caching_sha2_password 到 mysql_native_password auth-switch,并恢复 autocommit=1。

    Unhappy Path 覆盖

    1. reset 后读取临时表返回不存在错误;事务写入读回为 0,未发生跨借用会话泄漏。

    白盒验证

    pkg/frontend 的 TestMySQLWireChangeUserAuthSwitchAndRepeatedBorrow 与 TestMySQLWireResetConnectionPreservesDatabase 3 轮通过。

    回归测试

    已加入 motr#151:14_issue_regression.issue_27644_pooled_session_reset,涵盖真实 reset 与两次 change-user,MOTR 3 轮通过。

    测试证据

    每轮均验证同一物理连接、变量/临时表/事务清理,以及两次认证切换。

    测试结论

    测试通过。

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/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions