Skip to content

fix(frontend): preserve buffered TLS handshake bytes - #29996

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
daviszhen:codex/fix-29928-tls-buffer
Oct 12, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
daviszhen:codex/fix-29928-tls-buffer

Conversation

@daviszhen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #29928

What this PR does / why we need it:

Preserve bytes read ahead of the MySQL SSLRequest when upgrading to TLS. The TLS handoff now drains unread frontend buffer bytes before reading the underlying connection, and both handshake branches use the handoff. Added a real coalesced ClientHello TLS regression and post-handshake payload check.

@daviszhen
daviszhen requested a review from XuPeng-SH as a code owner October 12, 2026 08:07
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@daviszhen

Copy link
Copy Markdown
Contributor Author

Reviewed head 9ae4fe7886c3f7d5a4792ce5e427517e85e26e1c and all three changed files against base 7af631bdf79e7beb4bb3588e2bfd03ba4852b6cc.

Recommendation: approve from the code-review perspective, subject to required CI passing. No confirmed blocker in the buffered TLS handoff.

Conn.Read can leave bytes following SSLRequest in fixBuf. connForTLS copies precisely the unread range, resets the frontend buffer, and exposes that prefix before reading the raw connection. This avoids dropping the coalesced ClientHello without retaining an alias into a reusable buffer. The empty-prefix path preserves the original connection. Both server upgrade branches use the handoff and retain their existing handshake timeout/error handling; UseConn installs the resulting TLS connection afterward. Embedded net.Conn methods preserve writes, deadlines, addresses and close delegation.

Fresh exact-head validation with linked CGo:

  • Targeted ConnForTLS, handshake and IOSession tests passed, including the added real coalesced ClientHello handshake and decrypted payload test.
  • A temporary independent test pinned TLS 1.2 and TLS 1.3 separately, coalesced SSLRequest with ClientHello, completed the handshake, called Conn.UseConn(serverTLS), then sent a framed MySQL packet and decoded it via Conn.Read. Both versions returned the original payload and passed the connection allocator balance assertion.
  • Full PR git diff --check passed. No product code was modified.

The allocator assertion checks the repository connection buffers, not zero Go-heap retention. Temporary copied-prefix allocation is bounded by unread frontend buffer size. Local validation exercised the real TLS/packet handoff but not complete MOServer authentication or the native application replay from #29928. A durable post-UseConn MySQL framing regression would complement the current raw decrypted-payload assertion; this is non-blocking.

Current preflight passed, but build/UT/SCA/coverage and Connector/J E2E were still queued/running at posting time. Merge should wait for required CI. No full frontend suite, race build or distributed replay was run locally.

Ordinary PR comment only; no formal review state changed.

@XuPeng-SH

XuPeng-SH commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 9ae4fe7886c3f7d5a4792ce5e427517e85e26e1c

Assessment: request_changes

Reviewed the complete three-file delta, frozen comments, and affected connection lifecycle. The buffered TLS handoff fixes lost handshake bytes, but disables disconnect-triggered query cancellation for connections using the new wrapper.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

  • P2 pkg/frontend/mysql_buffer.go:379: On Linux/Darwin, a client coalesces SSLRequest and ClientHello, completes authentication, starts a long-running query, then disconnects.
    Impact: bufferedNetConn hides the underlying socket's syscall.Conn interface. The refreshed liveness probe consequently reports the disconnected connection as live, so its query continues until completion, another timeout, or explicit cancellation, retaining execution and transaction resources. Preserve socket access across the wrapper and add a TCP disconnect-after-upgrade regression.
    Evidence: Both server TLS branches install the wrapped connection through UseConn, which recreates livenessProbe (mysql_buffer.go:399-401). newSocketLivenessProbe unwraps only tls.Conn before asserting syscall.Conn (socket_liveness_unix.go:49-54); bufferedNetConn fails that assertion, leaving rawConn nil. The probe then always returns false,nil (lines 73-74), and routine_manager.go:235-250 skips beginClose. A standalone TCP probe using the verbatim wrapper confirmed that syscall.Conn remains hidden after the prefix drains, while the underlying socket returns EOF. Artifact: attempt-1/liveness-probe/result.log.

Validation:

  • Completed static review of buffer ownership, both handshake branches, timeout/error cleanup, callers, disconnect monitoring, compatibility, bounded costs, and all added tests.

  • Reused exact-head author evidence in comment 6120399544: linked-CGo targeted tests and TLS 1.2/1.3 coalesced handshake tests followed by UseConn, framed Conn.Read, and allocator checks.

  • Frozen exact-head CI reports successful build, Ubuntu UT, Linux SCA, coverage, Connector/J E2E, proxy BVT, and pessimistic multi-CN BVT.

  • Standalone TCP interface probe passed with Go 1.25.5 and CGO disabled. Diff whitespace and Go formatting checks passed; pinned source remained unchanged. Detailed audit saved in attempt-1/review-audit.json.

Limitations:

  • The standalone probe verifies the interface failure; it does not execute MOServer authentication or SQL cancellation. No local MatrixOne native suite was rerun.

  • The frozen bundle omits issue [Bug]: TLS handshake hangs when MySQL SSLRequest and ClientHello arrive together #29928's body and original native-client reproduction, limiting verification of the issue's full behavioral contract.

  • Performance costs were assessed structurally; no benchmark was run.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 9ae4fe7886c3f7d5a4792ce5e427517e85e26e1c

Assessment: request_changes

Reviewed the complete three-file delta, frozen comments, and affected connection lifecycle. The buffered TLS handoff fixes lost handshake bytes, but disables disconnect-triggered query cancellation for connections using the new wrapper.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

  • P2 pkg/frontend/mysql_buffer.go:379: On Linux/Darwin, a client coalesces SSLRequest and ClientHello, completes authentication, starts a long-running query, then disconnects.
    Impact: bufferedNetConn hides the underlying socket's syscall.Conn interface. The refreshed liveness probe consequently reports the disconnected connection as live, so its query continues until completion, another timeout, or explicit cancellation, retaining execution and transaction resources. Preserve socket access across the wrapper and add a TCP disconnect-after-upgrade regression.
    Evidence: Both server TLS branches install the wrapped connection through UseConn, which recreates livenessProbe (mysql_buffer.go:399-401). newSocketLivenessProbe unwraps only tls.Conn before asserting syscall.Conn (socket_liveness_unix.go:49-54); bufferedNetConn fails that assertion, leaving rawConn nil. The probe then always returns false,nil (lines 73-74), and routine_manager.go:235-250 skips beginClose. A standalone TCP probe using the verbatim wrapper confirmed that syscall.Conn remains hidden after the prefix drains, while the underlying socket returns EOF. Artifact: attempt-1/liveness-probe/result.log.

Validation:

  • Completed static review of buffer ownership, both handshake branches, timeout/error cleanup, callers, disconnect monitoring, compatibility, bounded costs, and all added tests.

  • Reused exact-head author evidence in comment 6120399544: linked-CGo targeted tests and TLS 1.2/1.3 coalesced handshake tests followed by UseConn, framed Conn.Read, and allocator checks.

  • Frozen exact-head CI reports successful build, Ubuntu UT, Linux SCA, coverage, Connector/J E2E, proxy BVT, and pessimistic multi-CN BVT.

  • Standalone TCP interface probe passed with Go 1.25.5 and CGO disabled. Diff whitespace and Go formatting checks passed; pinned source remained unchanged. Detailed audit saved in attempt-1/review-audit.json.

Limitations:

  • The standalone probe verifies the interface failure; it does not execute MOServer authentication or SQL cancellation. No local MatrixOne native suite was rerun.

  • The frozen bundle omits issue #29928's body and original native-client reproduction, limiting verification of the issue's full behavioral contract.

  • Performance costs were assessed structurally; no benchmark was run.

@daviszhen

Copy link
Copy Markdown
Contributor Author

已修复 reviewer 指出的 TLS 升级后断开探测问题。

改动:

  • bufferedNetConn 新增 SyscallConn(),转发底层 TCP 的 syscall.RawConn。
  • TLS UseConn 重建 socketLivenessProbe 后,可以继续探测真实 socket 的 FIN/断开,不再因 wrapper 隐藏 syscall.Conn 而永久认为连接存活。
  • 新增真实 TCP + coalesced SSLRequest/ClientHello + TLS 升级后关闭客户端的回归测试。

提交:109ee28b35。
本地验证通过:
go test ./pkg/frontend -run 'Test(ConnectionPeerClosedAfterBufferedTLSUpgrade|ConnForTLSCoalescedClientHello|ConnectionPeerClosed)' -count=1 -v
以及断开回归 -count=5。

@daviszhen
daviszhen force-pushed the codex/fix-29928-tls-buffer branch from 109ee28 to b042a34 Compare October 12, 2026 14:25
@daviszhen

Copy link
Copy Markdown
Contributor Author

静态检查修正已一并推送:errors.New 改为项目规范的 moerr.NewInternalErrorNoCtx。最终提交为 b042a34d5c;make err-check 与 frontend 目标测试均通过。

@daviszhen

Copy link
Copy Markdown
Contributor Author

Re-reviewed current head b042a34d5ca0afd3cc7410b04df1cd5b3c5a74e3, including the full four-file PR delta and the socket-liveness fix since 9ae4fe7886.

Recommendation: approve from the code-review perspective, subject to required CI passing. The syscall.Conn/disconnect-probe P2 raised by XuPeng-SH is addressed on this head; no new confirmed blocker.

The old wrapper did hide socket access. My earlier handshake/framed-read validation did not cover that lifecycle and was insufficient to exclude the regression. The current bufferedNetConn.SyscallConn forwards the non-owning RawConn handle, allowing newSocketLivenessProbe to unwrap tls.Conn and then reach the actual TCP socket through the buffered wrapper. UseConn refreshes the probe as before. Unsupported underlying connections return an explicit project-standard error, and the probe handles initialization errors without dereferencing a nil socket handle. No descriptor ownership or close behavior is transferred by this method.

Fresh exact-head validation with linked CGo, -count=3:

  • ConnForTLS and ConnectionPeerClosed test families passed, including the real TCP coalesced SSLRequest/ClientHello upgrade followed by raw-client close and detection of peer FIN.
  • My independent TLS 1.2/TLS 1.3 probe still passed: coalesced handshake, UseConn(serverTLS), then framed packet decoding through Conn.Read, with connection allocator balance checks.
  • Full PR git diff --check passed.

I traced the repaired probe into RoutineManager's long-running-request path, where a detected closure invokes beginClose. This establishes the socket-access/probe fix, but I did not independently execute complete MOServer authentication followed by a long-running SQL query and client disconnect. No full frontend suite, race build or native application replay was performed. No product code was modified; allocator balance is not a zero-Go-heap-retention claim.

Current-head preflight passed, while owning build/UT/SCA/coverage and Connector/J checks are not yet all complete. Merge should wait for required CI. This ordinary comment does not dismiss XuPeng-SH's formal review or submit a formal approval.

@XuPeng-SH

XuPeng-SH commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: b042a34d5ca0afd3cc7410b04df1cd5b3c5a74e3

Assessment: approve

Reviewed the complete four-file delta and frozen comments. The shared TLS handoff preserves buffered bytes, and SyscallConn forwarding resolves the previous disconnect-monitor regression. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

Validation:

  • Traced both handshake branches, buffer ownership, decrypted packet continuation, timeout/error cleanup, and disconnect detection through RoutineManager.beginClose.

  • Reused exact-head evidence in comment 6126303169: linked-CGo focused tests passed with count=3, including TCP disconnect after buffered TLS upgrade; TLS 1.2/1.3 probes also passed UseConn, framed Conn.Read, and allocator checks.

  • Frozen current-head CI records successful build, Ubuntu UT, SCA, coverage, Connector/J, proxy BVT, and pessimistic multi-CN BVT.

  • Local formatting and diff whitespace checks passed. HEAD and merge-base match; source remains clean. Audit saved in attempt-1/review-audit.json.

Limitations:

  • The frozen bundle omits issue [Bug]: TLS handshake hangs when MySQL SSLRequest and ClientHello arrive together #29928's body and original client reproducer; this assessment covers the described coalesced TLS handoff and affected lifecycle.

  • No local native suite or full authentication/long-query/disconnect replay was repeated. Reused behavioral evidence covers frontend connection and socket-probe boundaries; raw CI logs were not supplied.

  • Performance was assessed structurally, without benchmarks. Buffered upgrades add one bounded copy; its backing allocation may remain until connection reclamation.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: b042a34d5ca0afd3cc7410b04df1cd5b3c5a74e3

Assessment: approve

Reviewed the complete four-file delta and frozen comments. The shared TLS handoff preserves buffered bytes, and SyscallConn forwarding resolves the previous disconnect-monitor regression. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

Validation:

  • Traced both handshake branches, buffer ownership, decrypted packet continuation, timeout/error cleanup, and disconnect detection through RoutineManager.beginClose.

  • Reused exact-head evidence in comment 6126303169: linked-CGo focused tests passed with count=3, including TCP disconnect after buffered TLS upgrade; TLS 1.2/1.3 probes also passed UseConn, framed Conn.Read, and allocator checks.

  • Frozen current-head CI records successful build, Ubuntu UT, SCA, coverage, Connector/J, proxy BVT, and pessimistic multi-CN BVT.

  • Local formatting and diff whitespace checks passed. HEAD and merge-base match; source remains clean. Audit saved in attempt-1/review-audit.json.

Limitations:

  • The frozen bundle omits issue #29928's body and original client reproducer; this assessment covers the described coalesced TLS handoff and affected lifecycle.

  • No local native suite or full authentication/long-query/disconnect replay was repeated. Reused behavioral evidence covers frontend connection and socket-probe boundaries; raw CI logs were not supplied.

  • Performance was assessed structurally, without benchmarks. Buffered upgrades add one bounded copy; its backing allocation may remain until connection reclamation.

@mergify mergify Bot added the queued label Oct 12, 2026
@mergify

mergify Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-12 17:12 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-12 20:25 UTC · at c46a944689c78d50f11dbaa22dff013de7cd15d0

This pull request spent 3 hours 12 minutes 30 seconds in the queue, with no time running CI.

Reason

Pull request #29996 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 2f43dee into matrixorigin:main Oct 12, 2026
@mergify mergify Bot added dequeued and removed queued labels Oct 12, 2026
XuPeng-SH added a commit that referenced this pull request Nov 14, 2026
…32748)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #29928. Release-branch follow-up to #29996; discovered while
qualifying SDK #32671.

## What this PR does / why we need it:
On the actual `v4.2.8-hotfix` branch, the MySQL reader can consume
SSLRequest and TLS ClientHello together. Upgrading the raw socket then
loses the buffered TLS bytes, causing a pre-authentication hang or EOF.
Preserve that prefix at both TLS handoffs while forwarding the original
socket, deadlines and close/liveness operations.

This is the complete four-file backport of #29996, cherry-picked from
`2bc83b0b9a2` onto release base `c66030006fc`. It adds no client retry,
TLS fallback, catalog change or runner.

Validation on Linux/amd64, Go 1.26.4: all nine focused TLS/disconnect
roots pass normally and under race; the complete frontend package,
gofmt, go vet and incremental golangci-lint pass. An independent
real-service probe sends SSLRequest and ClientHello in a single write,
negotiates verified TLS 1.3 and authenticates `SELECT 1` successfully.
Source candidate identity is `8.0.30-MatrixOne-v4.2.8-hotfix`, git
`dbd8358db62`, binary SHA-256
`e16a080574bcc8a8ef7d3ddcaa990f0a86a45ce64a295023309f471261ae2688`.

This source candidate does not change the immutable published
`v4.2.8-hotfix-20261114` asset. That published binary still reproduces
the failure. Full SDK qualification and its distinct release/main
identities are tracked in #32671; no published release or production
deployment is performed here.

Complete SDK qualification against this actual release-branch build now
passes 1298/1298 online and 340/340 analytics cases with zero
failures/errors/skips. All required TLS, certificate/hostname rejection
and original Chinese-search assertions remain active. See #32671 for the
separate SDK hotfix-version fixes and immutable-release counterevidence.

Co-authored-by: davis zhen <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
XuPeng-SH pushed a commit to XuPeng-SH/matrixone that referenced this pull request Nov 15, 2026
)

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

issue matrixorigin#29928

Preserve bytes read ahead of the MySQL SSLRequest when upgrading to TLS.
The TLS handoff now drains unread frontend buffer bytes before reading
the underlying connection, and both handshake branches use the handoff.
Added a real coalesced ClientHello TLS regression and post-handshake
payload check.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 2f43dee)

This branch had an error being deployed

1 failed deployment
ci — c46a9446 Deployed Oct 12, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants