Repository navigation
Length-encode the info field of the MySQL OK packet - #107693
Merged
alexey-milovidov merged 3 commits intoJun 18, 2026
Merged
Conversation
`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]>
Contributor
|
Workflow [PR], commit [f0ec58a] Summary: ✅
AI ReviewSummaryThis PR fixes the MySQL wire Missing context / blind spots
Final VerdictStatus: ✅ Approve |
tiandiwonder
approved these changes
Jun 17, 2026
…connector-j-ok-packet
pull Bot
pushed a commit
to admariner/ClickHouse
that referenced
this pull request
Jun 17, 2026
The "new tests" check (`new_tests_check.py`) requires a bug-fix PR to add or modify a test. It previously only recognized changes to `tests/queries/0_stateless` (functional), `tests/integration/test_*` (integration), and `src/.../tests/` (unit) files. Docker images under `ci/docker/integration/` define the client and server environments that integration tests spin up (e.g. the MySQL and PostgreSQL client images). Bumping a client library version there - to exercise a fixed bug through an existing integration test - is effectively a test change, even though no `test_*.py` file is touched. Count such changes for this gate. This is added as a separate predicate rather than extending `has_new_integration_tests`, because the latter is also consulted by `filter_job.py` to enable the integration flaky and bugfix-validate jobs, which derive the test modules to run from changed `test_*.py` files and would have nothing to run for a Docker-image-only change. Found via the failed check in ClickHouse#107693 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 5/14 (35.71%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 7 line(s) · Uncovered code |
This was referenced Jun 18, 2026
robot-ch-test-poll3
added a commit
that referenced
this pull request
Jun 18, 2026
Cherry pick #107693 to 26.3: Length-encode the `info` field of the MySQL `OK` packet
This was referenced Jun 18, 2026
robot-ch-test-poll3
added a commit
that referenced
this pull request
Jun 18, 2026
Cherry pick #107693 to 26.4: Length-encode the `info` field of the MySQL `OK` packet
This was referenced Jun 18, 2026
robot-ch-test-poll3
added a commit
that referenced
this pull request
Jun 18, 2026
Cherry pick #107693 to 26.5: Length-encode the `info` field of the MySQL `OK` packet
alexey-milovidov
added a commit
that referenced
this pull request
Jun 18, 2026
Backport #107693 to 26.4: Length-encode the `info` field of the MySQL `OK` packet
alexey-milovidov
added a commit
that referenced
this pull request
Jun 18, 2026
Backport #107693 to 26.5: Length-encode the `info` field of the MySQL `OK` packet
robot-ch-test-poll4
added a commit
that referenced
this pull request
Jun 18, 2026
Cherry pick #107693 to 25.8: Length-encode the `info` field of the MySQL `OK` packet
alexey-milovidov
added a commit
that referenced
this pull request
Jun 30, 2026
…eclipse-temurin:21-jdk-alpine`
The `Dockers Build (amd)`/`Dockers Build (arm)` jobs failed because the
`clickhouse/mysql-java-client` image (rebuilt here due to the `Connector/J`
bump) still used the deprecated `openjdk:8-jdk-alpine` base, which the CI
`dockerhub-proxy` can no longer serve:
failed to resolve source metadata for docker.io/library/openjdk:8-jdk-alpine:
unexpected status from HEAD request to .../openjdk/manifests/8-jdk-alpine: 500 Internal Server Error
The failure is deterministic (it reproduced identically on a re-run ~2.5h
later), not a transient flake.
On `master` the base image had already been migrated to
`eclipse-temurin:21-jdk-alpine` (and `CLASSPATH` set to `.:`) in an earlier
commit that was never backported to `25.8`; #107693 was developed and verified
on top of that. The cherry-pick brought only the `Connector/J` 9.7.0 bump,
leaving `25.8` on the broken base image, so its image could not be rebuilt.
Align the `25.8` Dockerfile with the verified `master` configuration. Verified
locally: the image builds, the `Connector/J` 9.7.0 jar downloads, and
`MySQLJavaClientTest.java` (identical to `master`) compiles under JDK 21.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107889&sha=29e01838604f8a31671c7090e7ebcfa725b2a192&name_0=BackportPR&name_1=Dockers%20Build%20%28amd%29
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alexey-milovidov
added a commit
that referenced
this pull request
Jun 30, 2026
Backport #107693 to 26.3: Length-encode the `info` field of the MySQL `OK` packet
alexey-milovidov
added a commit
that referenced
this pull request
Jul 2, 2026
Backport #107693 to 25.8: Length-encode the `info` field of the MySQL `OK` packet
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
… the MySQL `OK` packet
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…7693 Backport ClickHouse#107693 to 26.4: Length-encode the `info` field of the MySQL `OK` packet
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
… the MySQL `OK` packet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #84542
MySQL Connector/J8.2.0 and newer (including 9.x) could not connect to the ClickHouse MySQL interface. The connection failed during driver setup withBuffer length is less than expected payload length.(the driver fails while running itsloadServerVariablesquery, before any user query runs).Root cause:
OKPacket::writePayloadImplwrote theinfo(human-readable status) field of theOKpacket as a plain rest-of-packet string wheneverCLIENT_SESSION_TRACKwas not negotiated. The protocol documentation describes the field that way, but a real MySQL server length-encodesinfounconditionally — I verified this 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 requestCLIENT_SESSION_TRACK.Connector/J>= 8.2 likewise readsinfoas 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 terminatingOKpacket, the driver interpreted the first byte of that summary (R,0x52) as a length and failed.Fix: always length-encode
info, matching what a real MySQL server sends.session_state_changesis still only present whenCLIENT_SESSION_TRACKandSERVER_SESSION_STATE_CHANGEDare set, and the human-readable summary is preserved.The
mysql-java-clientintegration image was pinned toConnector/J8.1.0 as a workaround for this bug; it is bumped to the current release (9.7.0) to cover the regression. Verified thatMySQLJavaClientTestproduces output identical tojava_client.referencewithConnector/J8.1.0, 9.3.0 and 9.7.0 (text and binary protocols), and that the bytes produced by the fix match a real MySQL server, soConnector/J9.3.0/9.7.0 andPyMySQLall connect successfully.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the MySQL interface being unusable with
MySQL Connector/J8.2.0 and newer (including 9.x). Theinfofield of theOKpacket is now length-encoded, matching the MySQL server, so the JDBC driver can connect.Documentation entry for user-facing changes
Version info
26.6.1.964(included in26.6and later)26.5.3.45,26.4.5.51,26.3.17.12,25.8.26.10