Skip to content

fix(cnservice): bound stale pipeline backend retries - #27528

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/issue-27523
Aug 24, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/issue-27523

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Aug 24, 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 #27523

What this PR does / why we need it:

  • Bounds Pipeline asynchronous backend-creation queue admission by the configured per-connect timeout.
  • Bounds the subsequent connect/retry phase by the same timeout, so a stale scheduled CN route can no longer inherit a potentially day-long SQL context. The two phases together have a finite upper bound of twice the configured timeout.
  • Keeps the originally scheduled CN endpoint fixed: recovery either establishes that route within budget or fails the statement; it never silently redirects work to another CN.
  • Removes the independent control client and active-stream lifetime bookkeeping. Those probes only ran after an already-created backend hit a read timeout, so they could not fix the reported initial backend-creation retry loop and introduced overlapping-stream lifecycle hazards.
  • Adds a regression test using the retryable RPC-timeout error produced by the backend connect loop, proving that Pipeline-specific options terminate retries before the query context expires.

Validation

  • ./pkg/cnservice/cnclient full tests
  • ./pkg/common/morpc full tests
  • ./pkg/sql/compile full tests
  • focused race stress (count=100) and full cnclient package race test
  • build, vet, diff checks, and conflict-free merge-tree against latest main

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

Deep review completed on exact head 97c7d7f02be064a7855f4268104cf8400d04b3f0.

[P1] The terminal liveness probe is bypassed by the actual pipeline-stream path, so the stale backend can still survive indefinitely. PipelineClient exposes NewStream, and stream sends set RPCMessage.stream=true. In remoteBackend.doWrite (pkg/common/morpc/backend.go:687-693), liveness tracking explicitly requires !f.send.stream, so stream traffic never establishes pendingSince. On every read timeout, keepDataConnectionAfterProbe (backend.go:1348-1352) sees oldestWritten == 0 and returns true before invoking the new independent control client. An active stream in rb.mu.activeStreams does not participate in this decision. Therefore a blackholed/removed CN with an active pipeline stream follows the same 120-second timeout loop forever; livenessProbeFailureIsTerminal is never reached, and the PR does not close issue #27523 for its primary call path.

I reproduced this deterministically without clock/network flakiness: create a backend with one active stream, a terminal liveness probe that returns endpoint gone, and a read-timeout error. Expected: false/retire and one probe call. Exact-head result: true/keep and zero probe calls.

Please make active stream state participate in the timeout/probe decision (with a generation-safe timestamp/progress contract), or track stream writes/progress explicitly. Preserve legitimately idle backends, but do not classify a backend owning an active pipeline stream as traffic-free. Add both a focused state-machine regression and an end-to-end NewPipelineClient stream test showing that a failed independent ping terminates the old stream/backend generation.

Q1/Q3 otherwise close: the control client is closed on data-client construction failure and normal shutdown, probe contexts are bounded/cancelable, and control/data backend counts remain bounded. The confirmed break is Q2: the active stream wait chain never reaches the newly added probe/termination edge. Existing full morpc/cnclient tests, build, vet, and diff checks pass because current tests exercise unary pending state or only client construction, not stream liveness. I did not wait for CI.

@XuPeng-SH XuPeng-SH changed the title fix(cnservice): retire stale pipeline backends after CN loss fix(cnservice): bound stale pipeline backend retries Aug 24, 2026
@matrix-meow matrix-meow added size/S Denotes a PR that changes [10,99] lines and removed size/M Denotes a PR that changes [100,499] lines labels Aug 24, 2026

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

Deep re-review completed on exact head 358b6a48bbcdfc7d64c2b780a88419954a259cd1.

No blockers. The prior request-changes findings were valid, and this revision removes the problematic control-probe/active-stream timestamp mechanism rather than adding more lifecycle state. Pipeline NewStream now directly bounds both global factory admission and the connect/retry phase for the originally scheduled endpoint. Initial backend creation against a stale CN therefore terminates within a finite Pipeline-specific budget and fails the statement without redirecting.

Validated the retryable RPC-timeout regression, full cnclient and morpc packages, sql/compile consumer, build/vet/diff checks, adaptive focused race stress at count=100, full cnclient race, and a conflict-free merge-tree against latest main. Independent final review also found no blockers. I did not wait for CI.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed exact head 358b6a48bbcdfc7d64c2b780a88419954a259cd1 against PR base main@b284c710e1da8854d6c28b4dfe8531731b7194ab.

No blockers. The Pipeline client now bounds both process-wide factory admission and the subsequent connect/retry phase with the configured per-connect timeout. This closes the initial stale-CN backend-creation hang while keeping the scheduled endpoint fixed and leaving unrelated MORPC clients on their existing policy. I traced the timeout, late factory completion, generation ownership, caller error cleanup, and capacity bounds; Q1-Q3 close without a new lifecycle edge.

Validated focused and full cnclient tests, full morpc tests, compile consumer failure cleanup, build/vet for cnclient, morpc, and compile, adaptive focused race stress at count=100, full cnclient race, diff checks, and a conflict-free merge-tree against latest main. CI was still running at review time.

@XuPeng-SH
XuPeng-SH merged commit 0aa7fc0 into matrixorigin:main Aug 24, 2026
26 checks passed
XuPeng-SH added a commit that referenced this pull request Aug 24, 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:

Backport of #27528 for `4.2-dev`.

Related issue: #27523.

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

- Bounds Pipeline asynchronous backend-creation queue admission by the
configured per-connect timeout.
- Bounds the subsequent connect/retry phase by the same timeout, so a
stale scheduled CN route cannot inherit a potentially day-long SQL
context.
- Keeps the scheduled CN endpoint fixed: recovery establishes that route
within budget or fails the statement; it does not silently redirect work
to another CN.
- Adds a regression using the retryable RPC-timeout error produced by
the backend connect loop.

The backport patch-id is identical to the final two-file diff of #27528.

## Validation

- `GOWORK=off go list -mod=readonly ./pkg/cnservice/cnclient`
- `GOWORK=off go build -mod=readonly ./pkg/cnservice/cnclient`
- `GOWORK=off go vet -mod=readonly ./pkg/cnservice/cnclient`
- focused `TestPipelineBackendCreateOptionsBoundRetry`
- full `./pkg/cnservice/cnclient` tests
- focused race stress: `TestPipelineBackendCreateOptionsBoundRetry`,
`-race -count=100`
- full `./pkg/cnservice/cnclient` race test
- full `./pkg/common/morpc` tests
- full `./pkg/sql/compile` tests
- `git diff --check`

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/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants