Skip to content

fix(proxy): clear backend handshake read deadline - #27377

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
daviszhen:fix/issue-27318
Aug 20, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
daviszhen:fix/issue-27318

Conversation

@daviszhen

@daviszhen daviszhen commented Aug 20, 2026 •

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 #27318

What this PR does / why we need it:

Fixes #27318.

The Proxy backend CN handshake uses the frontend IO session, whose reads apply the 24-hour SessionTimeout as an absolute socket read deadline. After authentication succeeds, the backend connection is handed to the long-lived tunnel without clearing that phase deadline. Long-lived Proxy-to-CN connections can therefore expire after roughly 24 hours and cause simultaneous client disconnects.

Changes

  • Clear the backend socket read deadline after a successful backend handshake and before returning the connection to the tunnel.
  • Propagate a deadline-clear failure through the existing handshake error path.
  • Add a regression test proving the handshake deadline is cleared.

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

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

P1: this clears the deadline only immediately after HandleHandshakeContext, but the same frontend IOSession re-arms SessionTimeout before every later protocol read (pkg/frontend/mysql_buffer.go:704-714). Both long-lived handoff paths perform such reads after this new clear: migration always executes SET transferred=1 and may replay SET statements through ExecStmtContext (pkg/proxy/conn_migration.go:123-146; pkg/proxy/server_conn.go:635-692), while cache Pop executes SET CONNECTION ID (pkg/proxy/conn_cache.go:485-505). Migration then returns the backend to the tunnel and cache Pop directly returns it at lines 537-546, with no second clear. Therefore migrated and cached/reused tunnels still inherit a new absolute read deadline and can disconnect roughly 24 hours later under active raw traffic. The added test only proves the intermediate post-handshake state. Please clear the phase-owned deadline at every terminal tunnel handoff (or make each bounded control-read phase restore it), and add deterministic post-ExecStmt migration/cache handoff coverage, including clear failure.

@daviszhen

Copy link
Copy Markdown
Contributor Author

Addressed the P1 deadline handoff issue in commit 3361edc9e4.

  • migrateConnToContext now clears the backend read deadline after SET transferred=1 and any replayed SET statements, immediately before the migration handoff.
  • connCache.PopContext clears the deadline after SET CONNECTION ID and discards the cached backend if clearing fails.
  • Added deterministic ExecStmtContext migration/cache tests for successful clearing and clear-failure paths.
  • Merged the latest upstream/main before pushing.

Please re-review the updated PR.

@daviszhen
daviszhen requested a review from XuPeng-SH August 20, 2026 07:22
@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/S Denotes a PR that changes [10,99] lines labels Aug 20, 2026

@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

No blocking or non-blocking findings. The prior deadline-handoff concern is addressed across handshake, migration, and cache reuse paths, including clear-failure handling.

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

Re-reviewed exact head 3361edc9e476add69d2baabfd318b0b75ef74151: APPROVED.

The previous blocker is closed across every terminal backend-to-tunnel handoff. Initial handshake clears the frontend IO read deadline before return; migration clears it after the final replay/control statement; cache reuse clears it after SET CONNECTION ID. No later step in those paths performs another backend protocol read before handoff. Clear failures remain fail-closed: migration returns the error and cache reuse discards the backend.

Focused controlled-CGo tests cover all three handoffs, re-arming after control reads, and both migration/cache clear-failure paths; they pass on this exact head. I found no remaining lifecycle or ownership blocker in the complete diff.

@mergify

mergify Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

queue

⚠️ Invalid commit message

Details

section not found

@mergify

mergify Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-20 12:08 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-20 18:32 UTC · at 028746244991d6e2853885e0f0a2cb20b8dfb18b · squash

This pull request spent 6 hours 24 minutes 11 seconds in the queue, including 47 minutes 33 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit 2073cfd into matrixorigin:main Aug 20, 2026
25 of 26 checks passed
@mergify mergify Bot removed the queued label Aug 20, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Fixes matrixorigin#27318.

The Proxy backend CN handshake uses the frontend IO session, whose reads apply the 24-hour `SessionTimeout` as an absolute socket read deadline. After authentication succeeds, the backend connection is handed to the long-lived tunnel without clearing that phase deadline. Long-lived Proxy-to-CN connections can therefore expire after roughly 24 hours and cause simultaneous client disconnects.

Approved by: @XuPeng-SH, @gouhongshen
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Fixes matrixorigin#27318.

The Proxy backend CN handshake uses the frontend IO session, whose reads apply the 24-hour `SessionTimeout` as an absolute socket read deadline. After authentication succeeds, the backend connection is handed to the long-lived tunnel without clearing that phase deadline. Long-lived Proxy-to-CN connections can therefore expire after roughly 24 hours and cause simultaneous client disconnects.

Approved by: @XuPeng-SH, @gouhongshen
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Fixes matrixorigin#27318.

The Proxy backend CN handshake uses the frontend IO session, whose reads apply the 24-hour `SessionTimeout` as an absolute socket read deadline. After authentication succeeds, the backend connection is handed to the long-lived tunnel without clearing that phase deadline. Long-lived Proxy-to-CN connections can therefore expire after roughly 24 hours and cause simultaneous client disconnects.

Approved by: @XuPeng-SH, @gouhongshen
XuPeng-SH added a commit that referenced this pull request Sep 27, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

issue #29406

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

Backport #27377 (`2073cfdfa566cf41e591e24a108f3ce22065f927`) to
`4.2-dev`.

The Proxy backend handshake uses frontend IOSession reads, which arm an
absolute socket read deadline using SessionTimeout (24 hours by
default). Without clearing it before handing the connection to the
long-lived tunnel, an actively used connection can expire approximately
24 hours after authentication. Migration control reads and cached
connection reuse can re-arm the same deadline.

This backport clears the phase-owned read deadline at all three
handoffs:

- Successful backend handshake, after joining the handshake worker and
cancellation interrupt.
- Migration, after the final control statement.
- Cached backend reuse, after SET CONNECTION ID.

A failed clear prevents handoff; cached backends that cannot be cleared
are discarded. Existing handshake, migration, cancellation, connection
ownership, and cache capacity protections are preserved. No timeout
setting, wire protocol, persistence format, or query execution behavior
changes.

Compatibility adaptation is limited to using the existing 4.2 `parent`
context for migration error attribution and keeping only this fix's
migration tests, without unrelated newer-main tests.

### Validation

Base: `6ca0a25ca5d5d3c8fe22d8587bc7e703cd034cac`.

Native artifacts were built with `make cgo` inside the isolated 4.2
worktree. Go version: `go1.26.4 darwin/arm64`.

- All five handoff/deadline regression tests passed, including migration
and cached-reuse clear failures.
- Full `pkg/proxy` suite passed with `-count=1 -timeout=300s` through
the repository CGo test wrapper.
- `git diff --check` passed.

The tests validate deadline state and failure ownership without waiting
24 hours. ### Compose CI repair on 4.2-dev

The first CI run failed before BVT SQL started: Quay rejected pulls for
the pinned MinIO server and mc images in both Compose lanes ([PROXY
job](https://github.com/matrixorigin/matrixone/actions/runs/36317763336/job/108627987240),
[PESSIMISTIC
job](https://github.com/matrixorigin/matrixone/actions/runs/36317763336/job/108627987185)).
The later log-export and coverage errors were consequences of Compose
never starting. This is the 4.2 backport of the merged main fix
[#29370](#29370), not a
proxy failure.

Compose now builds the **same pinned MinIO and mc releases** from their
official GitHub release binaries, verifies fixed SHA-256 hashes, and
preserves the server configuration. Bucket setup reports real mc errors
and tolerates an existing bucket on restart. Local validation passed:
Compose configuration, both image builds, healthy MinIO, public
`mo-test` bucket, repeated initialization, and `git diff --check`. The
full Compose BVT lanes remain subject to the new CI run.

A live 24-hour connection soak and multi-CN end-to-end validation were
not run. #29407 is a separate MORPC/Pipeline investigation and is not
claimed as fixed by this backport.

---------

Co-authored-by: davis zhen <[email protected]>
Co-authored-by: XuPeng-SH <[email protected]>

This branch was previously deployed

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

Labels

kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: [4.2-dev Stability] Sysbench, TPCC and Fulltext lose connections for 3 minutes without pod restart or OOM

4 participants