Skip to content

Cherry pick #107693 to 25.8: Length-encode the info field of the MySQL OK packet - #107819

Merged
robot-ch-test-poll4 merged 5 commits into
backport/25.8/107693from
cherrypick/25.8/107693
Jun 18, 2026
Merged

robot-ch-test-poll4 merged 5 commits into
backport/25.8/107693from
cherrypick/25.8/107693

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #107693

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

alexey-milovidov and others added 4 commits June 17, 2026 01:06
`MySQL Connector/J` 8.2.0 and newer (including 9.x) could not connect to the
ClickHouse MySQL interface; the connection failed during driver setup with
`Buffer length is less than expected payload length.`

Root cause: `OKPacket::writePayloadImpl` wrote the `info` (human-readable
status) field as a plain rest-of-packet string whenever `CLIENT_SESSION_TRACK`
was not negotiated. The MySQL protocol documentation describes the field that
way, but a real MySQL server length-encodes `info` unconditionally (verified
on the wire against MySQL 8.0, which sends e.g. `... 0x28 "Rows matched: 2
Changed: 2 Warnings: 0"` even when the client did not request
`CLIENT_SESSION_TRACK`). `Connector/J` >= 8.2 likewise reads `info` as a
length-encoded string regardless of the negotiated capabilities. Because
ClickHouse sends a non-empty summary (`Read N rows, ... in ... sec.`) in the
result-set terminating `OK` packet, `Connector/J` interpreted the first byte
of that summary (`R`, 0x52) as a length and failed. The driver issues the
triggering query (`loadServerVariables`) while opening the connection, so the
failure happens before any user query runs.

Fix: always length-encode `info`, matching what a real MySQL server sends.
`session_state_changes` is still only present when `CLIENT_SESSION_TRACK` and
`SERVER_SESSION_STATE_CHANGED` are set. The human-readable summary is kept.
Verified that `Connector/J` 9.3.0, `Connector/J` 8.1.0 and `PyMySQL` all
connect successfully, and that the produced bytes match a real MySQL server.

Closes: #84542

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `mysql-java-client` integration image was pinned to `Connector/J` 8.1.0
because 8.2.0+ could not connect to the ClickHouse MySQL interface (the `info`
field of the `OK` packet was written as a plain string while newer drivers read
it length-encoded). Now that `info` is length-encoded, bump the driver to the
current release (9.7.0) so the regression is covered.

Verified that `MySQLJavaClientTest` produces output identical to
`java_client.reference` with `Connector/J` 8.1.0, 9.3.0 and 9.7.0 (text and
binary protocols), so no reference update is needed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…or-j-ok-packet

Length-encode the `info` field of the MySQL `OK` packet
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants