Skip to content

[Bug]: JDBC Connection.setReadOnly is rejected although MySQL supports read-only connections #29185

Closed

Description

@Ariznawlll

Environment

  • MatrixOne: main@57c280ed48fdccec3c2eb25042820deaf1eca3c1
  • Topology: 1 Log / 1 TN / 2 CN / Proxy
  • Connector/J: 8.3.0
  • Control: MySQL 8.0 with the same Connector/J

What is wrong

The default Connector/J implementation of Connection.setReadOnly(true) sends SET SESSION TRANSACTION READ ONLY. MatrixOne rejects that statement, so Java frameworks and pools cannot initialize a JDBC connection as read-only:

errorCode=20105
sqlState=HY000
not supported: transaction access mode READ ONLY is not supported

This occurs before the application can execute a query. Direct CN1, direct CN2, and Proxy produced the same result in three independent rounds each.

MySQL 8.0 accepts the same JDBC call. The connection can execute reads, rejects writes while read-only, and accepts writes again after setReadOnly(false).

This also reverses the behavior recorded as fixed in #10059. That issue was closed as completed after both SET SESSION TRANSACTION READ ONLY and READ WRITE returned success.

Minimal reproduction

try (Connection c = DriverManager.getConnection(url, user, password);
     Statement s = c.createStatement()) {
    c.setReadOnly(true);       // MatrixOne returns 20105/HY000 here
    s.executeQuery("select 1");
    c.setReadOnly(false);
}

The Connector/J URL uses its default readOnlyPropagatesToServer=true behavior.

Reproduction matrix

Endpoint Attempts Result
CN1 (16001) 3 setReadOnly(true) rejected with 20105/HY000
CN2 (16002) 3 same
Proxy (6001) 3 same
MySQL 8.0 control 3 read-only switch, read enforcement, and switch back all work

Expected behavior

Connection.setReadOnly(true/false) should follow the MySQL JDBC contract. At minimum, a framework should be able to configure and use a read-only connection without the initialization call being rejected. If server-side read-only enforcement is implemented, writes must be rejected while the mode is active.

Evidence

The standalone probe is evidence/issue_26623/JdbcReadOnlyProbe.java in the local #26623 qualification evidence.

Activity

  1. added this to the MO-202609 milestone on Sep 23, 2026
  2. added theissue type on Sep 23, 2026
  3. added a commit that references this issue on Sep 25, 2026
    71c4157
  4. Ariznawlll commented on Sep 27, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5be6cd90b501da225be591ffffe6000bf01f515e
    • 部署方式:本地单机(1 CN / 1 TN / 1 LogService)
    • 测试日期:2026-09-27

    原问题验证

    在上述最新 main 上按 issue 原始复现步骤执行,并独立重复 3 次;3/3 均满足修复后的预期。当前 main 已包含修复提交 71c415705c909e524abd21dd0cf3e31b1c18e941。

    Happy Path 覆盖

    1. SET SESSION TRANSACTION READ ONLY/READ WRITE 均成功,两个兼容变量同步为 1/0,读连接可继续使用。

    Unhappy Path 覆盖

    1. 验证已合入契约:该模式用于 Connector/J 状态协商,不提供服务端写拦截;READ ONLY 下写入成功,切回后连接继续可用。

    白盒验证

    确认修复提交 71c415705c909e524abd21dd0cf3e31b1c18e941 是当前 main 的祖先,并核对对应 MatrixOne BVT/实现路径;本次另以公开 SQL 协议执行黑盒验收。

    回归测试

    已加入 MOTR PR #204 的 issue_28295_28594_29085_29185_compatibility.test,MOTR 提交 2b4462f2;本地基线比对连续 3 次通过。

    测试证据

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions