Skip to content

[4.2-dev] proxy: reject backend greetings with a mismatched connection ID - #33424

Merged
XuPeng-SH merged 5 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:codex/loom/33376-20261127T085112-4.2-dev
Nov 30, 2026
Merged

XuPeng-SH merged 5 commits into
matrixorigin:4.2-devfrom
iamlinjunhong:codex/loom/33376-20261127T085112-4.2-dev

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

What this PR does / why we need it:

Nine paired field timeouts showed different connection IDs at the Proxy and CN. The Proxy previously accepted the CN greeting and forwarded the client login, so the failure surfaced later as a backend authentication timeout. The field logs do not establish why the CN missed the connection preface.

The Proxy now checks the greeting against the ID it sent on that physical connection. A mismatch closes that candidate before forwarding login and lets the router try another eligible CN. The existing greeting-stage diagnostic includes both IDs and classifies the failure as non-timeout. Its structured connection_id is the request ID sent in ExtraInfo, including when the greeting is rejected. A candidate rejected during the greeting has no connection-manager registration to remove. Its cleanup preserves the live tunnel in the routing, drain, and connection-ID indexes, including when a Unix socket address alias selects the same CN. Closing a superseded backend also preserves the replacement's connection-ID entry. A separate pre-existing case remains when a candidate registers after a successful handshake and destination migration then fails.

The comparison runs once when opening a backend connection, before SQL execution.

Validation

  • A real MySQL driver logged in through Proxy and directly to a proxy-enabled CN. Both connections executed SELECT 1 and SELECT CONNECTION_ID().
  • The full pkg/proxy suite passed normally and under -race. Isolated backend tests cover zero and nonzero IDs, closure before login, retry on a healthy alternative, and registration ownership during migration.
  • Go vet, molint, and incremental golangci-lint passed for pkg/proxy.

After rebasing onto official 4.2-dev (57cd85573c), both original patches matched in git range-diff. On 1e91864079 (Go 1.26.4, Darwin arm64), mo-cgo-test -v -count=1 -timeout=180s ./pkg/proxy, mo-cgo-test -race -v -count=1 -timeout=240s ./pkg/proxy, and go vet -mod=readonly ./pkg/proxy passed. The MySQL driver smoke test and lint results above are from the original validation.

The review fix at cfbd93c894 was tested on official 4.2-dev (2bdc8daf52) with Go 1.26.4 on Darwin arm64. mo-cgo-test -count=1 -timeout=180s ./pkg/proxy and mo-cgo-test -race -count=1 -timeout=240s ./pkg/proxy passed. Focused race runs passed 54 iterations for backend greeting ownership and 100 for cached backend rebinding. go vet -mod=readonly ./pkg/proxy, molint, and incremental golangci-lint passed. The fake CN verifies Proxy rejection and index ownership. The real-CN timing and MySQL driver observations above come from the earlier validation.

The CI refresh at 19b151353a rebases the three unchanged Proxy patches onto official 4.2-dev (70bb7b3515), which includes the catalog DDL and focused restore test updates from #33458. On Darwin arm64 with Go 1.26.4, mo-cgo-test -short -race -tags matrixone_test -p 1 -count=3 passed both TestDropAccountWithMinimumRowLockCount and TestAlterPublicationExplicitTargetLockScope. The complete pkg/proxy suite passed in the same mode with -count=1. The earlier Linux x86 run passed Proxy but failed in the isolated catalog package, with a restore race and an unlock fatal during CN startup. The Linux x86 UT and CI Required checks passed on 19b151353a.

The handshake diagnostic follow-up at 3e4969685b90 was validated on Darwin arm64 with Go 1.26.4. Before the fix, two assertions reproduced a structured ID mismatch for request IDs 0 and 42. After the fix, TestRouter_BackendHandshakeConnectionID passed 20 repetitions under -race -tags matrixone_test. The full pkg/proxy suite passed normally and under -race -tags matrixone_test. Go vet, molint, and incremental golangci-lint passed. Linux CI for this follow-up will run after push.

Main PR: #33423

@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 →

@mergify

mergify Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@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.

Please close ownership on the new rejection path before merging. The greeting stage is the right place for the ID check, and the existing retry policy gives a bounded path to another eligible CN. The check adds one comparison per backend handshake. A single eligible CN still yields a fast connection failure in the mismatch case.

The full pkg/proxy suite passed under -race at 1e91864079. An additional probe through client.connectToBackend(prevAddr) isolated the ownership failure below. The different-CN mismatch control preserved both indexes.

A different CN with a matching greeting and successful auth can also overwrite the connection-ID entry before migration commits. When source export fails, candidate close removes that entry while the original tunnel remains active. I reproduced this on both this head and the clean base 57cd85573c. In 4.2-dev, handleKill still routes through SelectByConnID. Please scope the PR's failed-migration claim to the transition actually protected, or make registration transfer follow the existing migration commit point.

The two existing regression cases cover rejection before login, then retry and health accounting. Extend the ownership case to assert the drain and routing indexes as well as the ID entry. The issue's real-CN diagnostics establish the preface timing failure, and the PR's fake peer covers Proxy rejection. Keep those claims distinct.

Comment thread pkg/proxy/conn_manager.go Resolved
Comment thread pkg/proxy/server_conn.go Resolved
XuPeng-SH added a commit that referenced this pull request Nov 28, 2026
## What type of PR is this?

- [x] Test and CI

## Which issue(s) this PR fixes:

Related to #33429.

## What this PR does / why we need it:

Use the two existing UT Coverage groups for main and 4.2-dev. The legacy
and standby Shanghai paths share the prefix-scoped IDC fixture and
require successful basic and streaming-write tests. The manual OSS/COS
workflow tests the official 4.2-dev source and reports fixed identifiers
for both SDK and S3FS failures, even when provider metadata appears
later in the Go report. The manual check validates both configs before
source checkout and reports Go test timeouts separately.

[matrixorigin/CI#505](matrixorigin/CI#505) has
merged. All five references use the published commit
`d94028c93e14f8054a7cd4d1e2535bbaf59a8ec8`. Its tree is identical to the
reviewed CI head.

Linux actionlint, 140 companion CI tests, 86 MatrixOne CI tests and the
cross-repository retry and cleanup replay passed against the published
revision. Exact legacy workflow setup and pass gates were exercised with
local MinIO on both source branches. Healthy requests passed and invalid
credentials and zero-request reports failed. Replayed the real UT and
BVT profiles from [4.2-dev PR #33424, attempt
2](https://github.com/matrixorigin/matrixone/actions/runs/46107411827/attempts/2).
Removing the OSS/COS profile kept changed-code coverage at 100% and
changed overall block coverage from 76.784% to 76.752%. Live IDC/CS and
the manual provider run remain rollout checks.
@iamlinjunhong
iamlinjunhong force-pushed the codex/loom/33376-20261127T085112-4.2-dev branch from 1e91864 to cfbd93c Compare November 29, 2026 16:34
@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 19b151353a7c73a8738db1c84341641e861b0b15

Review completed. Read the assessment.

@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: 19b151353a7c73a8738db1c84341641e861b0b15

Assessment: request_changes

The greeting check and delayed manager registration address the reported mismatch and the earlier same-CN cleanup concern. The new mismatch failure, however, emits an incorrect structured connection ID, undermining correlation of the diagnostic this fix introduces. The separate post-authentication migration mapping issue discussed earlier is also present at the merge-base.

Model: gpt-6.1-terra / max

Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45

  • P2 pkg/proxy/handshake.go:290: A backend greeting reports a connection ID different from the ID sent in ExtraInfo.
    Impact: The resulting backend handshake failed event has an unrelated value in its structured connection_id field. Queries joining Proxy diagnostics by connection ID can miss the affected session or associate the event with another session, although the error text contains the expected and received IDs.
    Evidence: The early return occurs before s.connID is updated, leaving the independent counter assigned by newServerConnContext; logBackendHandshakeEvent logs that counter. An isolated extension of the existing mismatch test observed request ID 42 and structured connection_id 1001. Pre-greeting failures already had this logging weakness, but this change introduces the mismatch-specific failure path that encounters it. Emit the request-owned ID for this event and assert the structured field in the regression test.

Validation:

  • Private /tmp and loopback preflight passed: preflight.log and checks/1796019944336716700-3.json.

  • The complete pkg/proxy suite passed under -race, including a MySQL driver through Proxy with a controlled backend: proxy-package-race.log and checks/1796020456410010372-3.json.

  • The mismatch ownership test passed 55 race repetitions and the cached-connection rebinding test passed 100: handshake-stress.log, cache-stress.log, and their checks/1796020546905871081-3.json and checks/1796020552347582714-123.json receipts.

  • The nonzero-ID diagnostic overlay probe failed its structured-ID assertion as described: diagnostic-nonzero-probe.log and checks/1796020484243000091-4.json. The evidence audit verified the overlay, source fingerprint, native inputs, discussion coverage, and receipts: evidence-audit.log and checks/1796020653270594218-5.json.

Limitations:

  • The reported real-CN preface timing diagnostic and direct/Proxy driver smoke were not independently repeated; the supplied PR evidence contains author-reported results without retained raw logs.

  • The separate post-authentication failed-migration ID-map issue remains outside this PR's regression scope. In the normal handler, connection-ID lookup uses the SQL worker; the connection-manager lookup is used by the test-mode handler.

@gouhongshen gouhongshen 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.

Codex automated review

The change is correct and I found no blocking or non-blocking defects beyond what the prior review already raised and the head already addresses. The proxy now parses the backend greeting with the standalone parseBackendConnID and rejects it whenever the ID differs from the request-owned CNServer.connID that connectContext wrote into the ExtraInfo preface; the CN side is verified (mysql_protocol.go:3910 adopts ExtraInfo.ConnectionID and echoes it in the greeting at :1648), so a healthy path always matches and only the preface-miss failure mode observed in issue #33376 is rejected. The rejection happens before the login packet is forwarded, is classified as a retryable non-timeout connectErr, does not trip the CN health breaker, and lets clientConn.connectToBackendContext retry another eligible CN; on exhaustion the client connection fails fast instead of consuming the 10s auth deadline. Both inline findings from the existing CHANGES_REQUESTED review are fixed in this head and I verified the fixes in code: manager/tunnel ownership moved from construction to a post-handshake register() call (router.go, server_conn.go), so a rejected candidate's Close can no longer remove a live tunnel from the routing, drain, or connection-ID indexes, including the same-UUID Unix address alias case; the new regression test asserts all three indexes plus the ID entry, as requested. The connIDServers pointer-identity guard in connManager.disconnect also stops a superseded source backend from deleting the replacement's entry, an improvement over the base's unconditional delete. The bounds check now also validates len(p.Payload), where the base could slice out of range on a malformed packet. The remaining known gap (a candidate that registers after a successful handshake and then fails during migration removes the connection-ID entry) reproduces on clean 4.2-dev per the prior reviewer, and the PR description now scopes its claim to exclude it exactly as that reviewer requested, so I do not report it as a finding. Test limitation: I could not execute the pkg/proxy suite or even complete go vet in this checkout because the pkg/proxy dependency closure (per a decoded go list -deps -test snapshot, 2159 packages, no errors, no DepsErrors) includes github.com/matrixorigin/matrixone/cgo, which requires thirdparties build products (xxhash.h, roaring.h, usearch.h headers and -lusearch_c/-lroaring from thirdparties/install) that are absent in this worktree; building them with make cgo/make thirdparties is outside review scope. go vet ./pkg/proxy exited 1 at cgo compile with those missing headers (log saved under $TMPDIR), and gofmt over pkg/proxy is clean. Supporting execution evidence comes from the PR record: the prior reviewer ran the full suite under -race, and the author reports rebase-identical patches passing the proxy suite, focused race iterations, and lint on this 4.2-dev base.

@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 19b151353a7c73a8738db1c84341641e861b0b15

New discussion was assessed; the previous review remains unchanged.

@XuPeng-SH

XuPeng-SH commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 3e4969685b90e488b721c58c84d5ce667c1bf5bf

Review completed. Read the assessment.

@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: 3e4969685b90e488b721c58c84d5ce667c1bf5bf

Assessment: approve

The greeting check, deferred registration, and request-owned diagnostic ID address the prior review concerns. The change uses the existing handshake and connection-manager ownership paths. The separate post-authentication migration ID-map issue predates this change.

Model: gpt-6.1-terra / max

Session: 01a22aff-bb68-7e31-ae71-ee4ab48ad9d0 · slot 0 · generation 45

Validation:

  • Private /tmp and loopback preflight passed.

  • Current-head race-enabled proxy tests passed for greeting IDs, retry, same-CN cleanup, diagnostics, timeout handling, and cached-connection rebinding; receipt 1796034259837783701-3.json.

  • Reused the prior full proxy race-suite result for unchanged paths after comparing the intervening source changes and its retained receipt.

  • The captured CI snapshot reports successful Linux/x86 unit tests, Linux/arm64 SCA, and proxy and pessimistic multi-CN BVT.

Limitations:

  • The author's real-CN delayed-preface diagnostic and direct/Proxy MySQL driver smoke tests were not independently repeated.

@mergify mergify Bot added the queued label Nov 30, 2026
@mergify

mergify Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

34 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Mon 30 Nov, 10:43 · rule release-4.2 · triggered by rule Automatic queue on approval for release-4.2
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 11:17 · 8cb44a5

Reason

Pull request #33424 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.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

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

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

@XuPeng-SH
XuPeng-SH merged commit ab9b731 into matrixorigin:4.2-dev Nov 30, 2026
21 of 27 checks passed
@mergify mergify Bot added dequeued and removed queued labels Nov 30, 2026

This branch was successfully deployed

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

Labels

dequeued 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.

4 participants