Repository navigation
[4.2-dev] fix(proxy): clear backend handoff read deadlines - #29408
Conversation
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 (cherry picked from commit 2073cfd)
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Both Compose BVT lanes on PR matrixorigin#29408 stop before SQL when Quay rejects pulls of the pinned MinIO server and mc images. Backport the tested main-branch fix from matrixorigin#29370: build those same binary releases from upstream GitHub assets and verify their SHA-256 hashes. Keep the existing MinIO configuration and make bucket setup fail on real mc errors while remaining safe to repeat after a restart. Validation: Compose config, both image builds, healthy MinIO, public mo-test bucket, repeated bucket setup, and diff check passed locally. (cherry picked from commit 44e5226)
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed commit 6cbaf57fd1f51cd1e42562d9bc17a11221f50de5 against 4.2-dev@6ca0a25ca5d5d3c8fe22d8587bc7e703cd034cac (also the merge-base), including both the proxy backport and Compose repair.
No merge-blocking code findings were identified. The expected behavior is appropriate: an absolute deadline owned by handshake/control reads must not expire a connection after ownership moves to a long-lived tunnel. Handshake and migration cancellation still have their own bounded contexts; clearing the read deadline is not a change to those bounds.
| Boundary | Closure checked | Result |
|---|---|---|
| Initial handshake | Join worker and cancellation callback → clear deadline → router/tunnel handoff; error → router closes backend | Correct ordering; no late callback owns the successful connection |
| Migration | Final replay SQL → clear deadline → migration RPC → publish replacement; error → close candidate and retry/terminate | RPC uses a separate transport; no subsequent local SQL read re-arms this backend before handoff |
| Cache reuse | Join old tunnel generation → SET CONNECTION ID → clear deadline → authenticate and transfer ownership | Clear failure discards and closes the candidate; cache Close retains ownership of in-flight candidates |
| Resource/cancellation | Socket, protocol buffers, cache bookkeeping, phase cancellation, terminal cleanup | No added leak, double-cleanup, unbounded queue, or wait dependency found |
| Performance/design | Full production diff and raw tunnel consumers | One deadline clear per handoff; no per-query/per-packet check, worker, timer, retained buffer, or new configurable mechanism. The existing RawConn accessor can create a short-lived wrapper, confined to migration/cache handoff |
| Compose | Official release URLs, fixed hashes/base digest, platform, healthcheck, bucket setup | Same MinIO/mc versions; linux/amd64 is explicit. Initialization propagates real errors and tolerates an existing bucket |
Validation on Linux/amd64, Go 1.26.4, using the repository CGo wrapper and native library rebuilt in the review worktree:
- All 5 added regressions passed under race detection. Replacing only the three changed production Go files with their 4.2-dev implementations via a Go overlay made all 5 fail at the deadline/handoff assertions. This confirms they detect the original behavior.
- Full
pkg/proxy: normal and race runs both passed (242 top-level tests; 421 including subtests). Test execution took 19.042s and 20.653s respectively, excluding compilation. - Each of the 5 new regressions and 7 directly affected cancellation/ownership/reuse tests passed its own exact-name
-race -count=100 -timeout=120srun. Repetition selection used B=30s, measured T=0–0.11s, capped at N=100. - Review-only overlay tests also passed 100 race repetitions: actual handshake deadline-clear failure rejects the response; cancelling the old context after successful handshake leaves the backend usable for real protocol I/O. These are additional review evidence, not claimed as committed regression coverage.
go build,go vet, andgit diff --checkpassed. Worktree is clean.- Unchanged Compose repair retains this session's successful image-build/healthcheck/public-bucket/repeated-initialization smoke evidence. Full multi-CN BVT was not run locally.
Merge/acceptance limits: this is a COMMENT review, not an assertion that merge gates are green. In the current CI run, upstream jobs were cancelled and the required summary failed with matrixone-ci: cancelled; Compose BVT did not execute. Required CI still needs to complete successfully. Issue #29406 also explicitly requires a deployment soak exceeding 24 hours with Sysbench error counters and TPCC consistency checks; local deadline tests do not establish that operational acceptance, and the issue should not be declared verified on that basis alone.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Approved commit 6cbaf57 against 4.2-dev@6ca0a25ca5d5d3c8fe22d8587bc7e703cd034cac. The PR head and base are unchanged from the completed deep review.
No blocking code findings. Full review and validation evidence: #29408 (review)
Required CI must still pass before merging. The deployment soak and consistency acceptance specified in #29406 remain outstanding; this code approval does not claim those have completed.
What type of PR is this?
Which issue(s) this PR fixes:
issue #29406
What this PR does / why we need it:
Backport #27377 (
2073cfdfa566cf41e591e24a108f3ce22065f927) to4.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:
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
parentcontext 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 cgoinside the isolated 4.2 worktree. Go version:go1.26.4 darwin/arm64.pkg/proxysuite passed with-count=1 -timeout=300sthrough the repository CGo test wrapper.git diff --checkpassed.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, PESSIMISTIC job). 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, 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-testbucket, repeated initialization, andgit 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.