Skip to content

fix(morpc): preserve slow responses after probe timeout - #26903

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/morpc-preserve-slow-lock-responses
Aug 10, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/morpc-preserve-slow-lock-responses

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

Related to #26888

What this PR does / why we need it:

A MORPC data backend currently treats a failed independent liveness probe as
proof that the data connection is dead. For lock RPCs this is unsafe: a valid
remote lock wait may be longer than the 10-second backend read timeout, and the
independent control connection can time out while the owner is still processing
and later returns a valid response.

In that interleaving, the failed probe resets the shared data backend and fails
all pending Futures together. The TPCC run in #26888 observed this fan-out as 88
ErrorCode 20505 failures; the lock owner attempted to return the pending
responses shortly after the caller had already closed the backend.

This PR changes only the response-inactivity path:

  • seal the inactive data generation from new admission before probing;
  • preserve its pending Futures regardless of the independent probe result;
  • let new demand use the existing bounded replacement-generation mechanism;
  • leave immediate reset behavior unchanged for terminal data errors such as
    EOF, connection reset, and broken pipe.

The control transport is independent, so its timeout is treated as
inconclusive rather than as evidence that the data connection cannot still
make progress. Resource growth remains bounded: the client permits at most one
extra draining generation per remote and retires the oldest drain if its
replacement also stalls.

The normal request/response path does not acquire new locks, allocate new
objects, or issue additional RPCs. The behavior changes only after unary data
traffic has remained inactive for the configured backend read timeout.

Validation

  • Pre-fix counterfactual: the new regression test fails on current main
    because the timed-out probe leaves the backend admissible and then resets it.
  • go test -count=30 for the focused liveness/generation tests.
  • go test -race -count=100 -run '^TestTimedOutLivenessProbePreservesSlowDataResponse$' ./pkg/common/morpc
  • go test -race -count=1 ./pkg/common/morpc
  • go test -count=1 ./pkg/common/morpc/...
  • go test -count=1 ./pkg/lockservice/...
  • go build ./pkg/common/morpc/... ./pkg/lockservice/...
  • go vet ./pkg/common/morpc/... ./pkg/lockservice/...

@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 reviewed exact head aa11c18f2a3d6a2609eaa425ae50b51ce72c321f with the MORPC unhappy-path ownership and wait-for graph.

The change correctly makes a failed independent control probe inconclusive: it seals new admission before probing while leaving the old data generation as owner of pending Futures. Late data responses can still complete; request deadlines and Future Close release abandoned work; terminal data errors still take the existing immediate reset/fail path; client/backend Close remains the final teardown owner. Replacement growth remains bounded, with the oldest draining generation retired before another replacement is admitted.

Local validation passed: focused liveness/generation tests x30, full pkg/common/morpc, full MORPC race (plus the new regression x30 under race), pkg/lockservice/..., build, vet, and diff check. No blocking correctness, lifecycle, deadlock, or unbounded-growth issue found.

@mergify mergify Bot added the queued label Aug 10, 2026
@mergify

mergify Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-10 07:50 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-10 08:41 UTC · at 6173bbb1ea08cbcf2ae1ef2849b32501874484e5 · squash

This pull request spent 50 minutes 14 seconds in the queue, including 49 minutes 37 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 Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • 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

XuPeng-SH pushed a commit that referenced this pull request Aug 10, 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:

Fixes #26922

Related to #26888 and #26903.

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

### Root cause

When a remote Lock response is lost or times out, the source CN records
the requested rows in `activeTxn.tableKeys` so transaction close can
conservatively send Unlock. The same collection is also consumed by
distributed deadlock detection as proof that the transaction holds each
row.

If the request is still waiting on the owner, that cleanup-only record
makes the owner return the same transaction as its own waiter and
produces a false `T <= T` cycle. This exactly matches the three
transaction-correlated self-cycles observed in #26888.

### Fix

- Keep uncertain rows in `tableKeys`, preserving conservative cleanup
and preventing remote lock leaks.
- Track only cleanup-only rows in a sparse per-table set and exclude
them from `fetchWhoWaitingMe`.
- Promote an uncertain row when a later Lock result confirms
acquisition.
- Never downgrade an already confirmed row when a later retry has an
uncertain result.
- Remove sparse state on lock removal, table cleanup, transaction close,
and object reuse.

No RPC/wire format changes are required. Normal successful Lock calls do
not allocate the sparse state. Proxy-confirmed shared holders keep the
existing deadlock-graph behavior.

### State transitions

| Current state | Event | Next state | Cleanup | Deadlock graph |
| --- | --- | --- | --- | --- |
| absent | remote response uncertain | uncertain | included | excluded |
| uncertain | successful Lock result | confirmed | included | included |
| confirmed | remote response uncertain | confirmed | included |
included |
| either | lock/transaction cleanup | absent | removed | removed |

### Tests

- Added a deterministic two-service regression reproducing the false
self-edge while preserving a real confirmed remote-holder edge.
- Added transition coverage for uncertain, promoted, non-downgraded, and
removed rows.
- Extended the existing remote timeout cleanup test to assert
cleanup-only state.
- Focused tests: `-count=100` passed.
- Each focused test under race: `-count=100` passed.
- `go test ./pkg/lockservice` passed.
- `go test -race ./pkg/lockservice` passed.
- `go vet ./pkg/lockservice` passed.

No 4.2 backport is planned for this PR.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26903)

A MORPC data backend currently treats a failed independent liveness probe as
proof that the data connection is dead. For lock RPCs this is unsafe: a valid
remote lock wait may be longer than the 10-second backend read timeout, and the
independent control connection can time out while the owner is still processing
and later returns a valid response.

In that interleaving, the failed probe resets the shared data backend and fails
all pending Futures together. The TPCC run in matrixorigin#26888 observed this fan-out as 88
ErrorCode 20505 failures; the lock owner attempted to return the pending
responses shortly after the caller had already closed the backend.

This PR changes only the response-inactivity path:

- seal the inactive data generation from new admission before probing;
- preserve its pending Futures regardless of the independent probe result;
- let new demand use the existing bounded replacement-generation mechanism;
- leave immediate reset behavior unchanged for terminal data errors such as
EOF, connection reset, and broken pipe.

The control transport is independent, so its timeout is treated as
inconclusive rather than as evidence that the data connection cannot still
make progress. Resource growth remains bounded: the client permits at most one
extra draining generation per remote and retires the oldest drain if its
replacement also stalls.

The normal request/response path does not acquire new locks, allocate new
objects, or issue additional RPCs. The behavior changes only after unary data
traffic has remained inactive for the configured backend read timeout.

### Validation

- Pre-fix counterfactual: the new regression test fails on current `main`
because the timed-out probe leaves the backend admissible and then resets it.
- `go test -count=30` for the focused liveness/generation tests.
- `go test -race -count=100 -run '^TestTimedOutLivenessProbePreservesSlowDataResponse$' ./pkg/common/morpc`
- `go test -race -count=1 ./pkg/common/morpc`
- `go test -count=1 ./pkg/common/morpc/...`
- `go test -count=1 ./pkg/lockservice/...`
- `go build ./pkg/common/morpc/... ./pkg/lockservice/...`
- `go vet ./pkg/common/morpc/... ./pkg/lockservice/...`

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#26925)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26922

Related to matrixorigin#26888 and matrixorigin#26903.

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

### Root cause

When a remote Lock response is lost or times out, the source CN records
the requested rows in `activeTxn.tableKeys` so transaction close can
conservatively send Unlock. The same collection is also consumed by
distributed deadlock detection as proof that the transaction holds each
row.

If the request is still waiting on the owner, that cleanup-only record
makes the owner return the same transaction as its own waiter and
produces a false `T <= T` cycle. This exactly matches the three
transaction-correlated self-cycles observed in matrixorigin#26888.

### Fix

- Keep uncertain rows in `tableKeys`, preserving conservative cleanup
and preventing remote lock leaks.
- Track only cleanup-only rows in a sparse per-table set and exclude
them from `fetchWhoWaitingMe`.
- Promote an uncertain row when a later Lock result confirms
acquisition.
- Never downgrade an already confirmed row when a later retry has an
uncertain result.
- Remove sparse state on lock removal, table cleanup, transaction close,
and object reuse.

No RPC/wire format changes are required. Normal successful Lock calls do
not allocate the sparse state. Proxy-confirmed shared holders keep the
existing deadlock-graph behavior.

### State transitions

| Current state | Event | Next state | Cleanup | Deadlock graph |
| --- | --- | --- | --- | --- |
| absent | remote response uncertain | uncertain | included | excluded |
| uncertain | successful Lock result | confirmed | included | included |
| confirmed | remote response uncertain | confirmed | included |
included |
| either | lock/transaction cleanup | absent | removed | removed |

### Tests

- Added a deterministic two-service regression reproducing the false
self-edge while preserving a real confirmed remote-holder edge.
- Added transition coverage for uncertain, promoted, non-downgraded, and
removed rows.
- Extended the existing remote timeout cleanup test to assert
cleanup-only state.
- Focused tests: `-count=100` passed.
- Each focused test under race: `-count=100` passed.
- `go test ./pkg/lockservice` passed.
- `go test -race ./pkg/lockservice` passed.
- `go vet ./pkg/lockservice` passed.

No 4.2 backport is planned for this PR.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26903)

A MORPC data backend currently treats a failed independent liveness probe as
proof that the data connection is dead. For lock RPCs this is unsafe: a valid
remote lock wait may be longer than the 10-second backend read timeout, and the
independent control connection can time out while the owner is still processing
and later returns a valid response.

In that interleaving, the failed probe resets the shared data backend and fails
all pending Futures together. The TPCC run in matrixorigin#26888 observed this fan-out as 88
ErrorCode 20505 failures; the lock owner attempted to return the pending
responses shortly after the caller had already closed the backend.

This PR changes only the response-inactivity path:

- seal the inactive data generation from new admission before probing;
- preserve its pending Futures regardless of the independent probe result;
- let new demand use the existing bounded replacement-generation mechanism;
- leave immediate reset behavior unchanged for terminal data errors such as
EOF, connection reset, and broken pipe.

The control transport is independent, so its timeout is treated as
inconclusive rather than as evidence that the data connection cannot still
make progress. Resource growth remains bounded: the client permits at most one
extra draining generation per remote and retires the oldest drain if its
replacement also stalls.

The normal request/response path does not acquire new locks, allocate new
objects, or issue additional RPCs. The behavior changes only after unary data
traffic has remained inactive for the configured backend read timeout.

### Validation

- Pre-fix counterfactual: the new regression test fails on current `main`
because the timed-out probe leaves the backend admissible and then resets it.
- `go test -count=30` for the focused liveness/generation tests.
- `go test -race -count=100 -run '^TestTimedOutLivenessProbePreservesSlowDataResponse$' ./pkg/common/morpc`
- `go test -race -count=1 ./pkg/common/morpc`
- `go test -count=1 ./pkg/common/morpc/...`
- `go test -count=1 ./pkg/lockservice/...`
- `go build ./pkg/common/morpc/... ./pkg/lockservice/...`
- `go vet ./pkg/common/morpc/... ./pkg/lockservice/...`

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#26925)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26922

Related to matrixorigin#26888 and matrixorigin#26903.

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

### Root cause

When a remote Lock response is lost or times out, the source CN records
the requested rows in `activeTxn.tableKeys` so transaction close can
conservatively send Unlock. The same collection is also consumed by
distributed deadlock detection as proof that the transaction holds each
row.

If the request is still waiting on the owner, that cleanup-only record
makes the owner return the same transaction as its own waiter and
produces a false `T <= T` cycle. This exactly matches the three
transaction-correlated self-cycles observed in matrixorigin#26888.

### Fix

- Keep uncertain rows in `tableKeys`, preserving conservative cleanup
and preventing remote lock leaks.
- Track only cleanup-only rows in a sparse per-table set and exclude
them from `fetchWhoWaitingMe`.
- Promote an uncertain row when a later Lock result confirms
acquisition.
- Never downgrade an already confirmed row when a later retry has an
uncertain result.
- Remove sparse state on lock removal, table cleanup, transaction close,
and object reuse.

No RPC/wire format changes are required. Normal successful Lock calls do
not allocate the sparse state. Proxy-confirmed shared holders keep the
existing deadlock-graph behavior.

### State transitions

| Current state | Event | Next state | Cleanup | Deadlock graph |
| --- | --- | --- | --- | --- |
| absent | remote response uncertain | uncertain | included | excluded |
| uncertain | successful Lock result | confirmed | included | included |
| confirmed | remote response uncertain | confirmed | included |
included |
| either | lock/transaction cleanup | absent | removed | removed |

### Tests

- Added a deterministic two-service regression reproducing the false
self-edge while preserving a real confirmed remote-holder edge.
- Added transition coverage for uncertain, promoted, non-downgraded, and
removed rows.
- Extended the existing remote timeout cleanup test to assert
cleanup-only state.
- Focused tests: `-count=100` passed.
- Each focused test under race: `-count=100` passed.
- `go test ./pkg/lockservice` passed.
- `go test -race ./pkg/lockservice` passed.
- `go vet ./pkg/lockservice` passed.

No 4.2 backport is planned for this PR.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…#26903)

A MORPC data backend currently treats a failed independent liveness probe as
proof that the data connection is dead. For lock RPCs this is unsafe: a valid
remote lock wait may be longer than the 10-second backend read timeout, and the
independent control connection can time out while the owner is still processing
and later returns a valid response.

In that interleaving, the failed probe resets the shared data backend and fails
all pending Futures together. The TPCC run in matrixorigin#26888 observed this fan-out as 88
ErrorCode 20505 failures; the lock owner attempted to return the pending
responses shortly after the caller had already closed the backend.

This PR changes only the response-inactivity path:

- seal the inactive data generation from new admission before probing;
- preserve its pending Futures regardless of the independent probe result;
- let new demand use the existing bounded replacement-generation mechanism;
- leave immediate reset behavior unchanged for terminal data errors such as
EOF, connection reset, and broken pipe.

The control transport is independent, so its timeout is treated as
inconclusive rather than as evidence that the data connection cannot still
make progress. Resource growth remains bounded: the client permits at most one
extra draining generation per remote and retires the oldest drain if its
replacement also stalls.

The normal request/response path does not acquire new locks, allocate new
objects, or issue additional RPCs. The behavior changes only after unary data
traffic has remained inactive for the configured backend read timeout.

### Validation

- Pre-fix counterfactual: the new regression test fails on current `main`
because the timed-out probe leaves the backend admissible and then resets it.
- `go test -count=30` for the focused liveness/generation tests.
- `go test -race -count=100 -run '^TestTimedOutLivenessProbePreservesSlowDataResponse$' ./pkg/common/morpc`
- `go test -race -count=1 ./pkg/common/morpc`
- `go test -count=1 ./pkg/common/morpc/...`
- `go test -count=1 ./pkg/lockservice/...`
- `go build ./pkg/common/morpc/... ./pkg/lockservice/...`
- `go vet ./pkg/common/morpc/... ./pkg/lockservice/...`

Approved by: @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…origin#26925)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26922

Related to matrixorigin#26888 and matrixorigin#26903.

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

### Root cause

When a remote Lock response is lost or times out, the source CN records
the requested rows in `activeTxn.tableKeys` so transaction close can
conservatively send Unlock. The same collection is also consumed by
distributed deadlock detection as proof that the transaction holds each
row.

If the request is still waiting on the owner, that cleanup-only record
makes the owner return the same transaction as its own waiter and
produces a false `T <= T` cycle. This exactly matches the three
transaction-correlated self-cycles observed in matrixorigin#26888.

### Fix

- Keep uncertain rows in `tableKeys`, preserving conservative cleanup
and preventing remote lock leaks.
- Track only cleanup-only rows in a sparse per-table set and exclude
them from `fetchWhoWaitingMe`.
- Promote an uncertain row when a later Lock result confirms
acquisition.
- Never downgrade an already confirmed row when a later retry has an
uncertain result.
- Remove sparse state on lock removal, table cleanup, transaction close,
and object reuse.

No RPC/wire format changes are required. Normal successful Lock calls do
not allocate the sparse state. Proxy-confirmed shared holders keep the
existing deadlock-graph behavior.

### State transitions

| Current state | Event | Next state | Cleanup | Deadlock graph |
| --- | --- | --- | --- | --- |
| absent | remote response uncertain | uncertain | included | excluded |
| uncertain | successful Lock result | confirmed | included | included |
| confirmed | remote response uncertain | confirmed | included |
included |
| either | lock/transaction cleanup | absent | removed | removed |

### Tests

- Added a deterministic two-service regression reproducing the false
self-edge while preserving a real confirmed remote-holder edge.
- Added transition coverage for uncertain, promoted, non-downgraded, and
removed rows.
- Extended the existing remote timeout cleanup test to assert
cleanup-only state.
- Focused tests: `-count=100` passed.
- Each focused test under race: `-count=100` passed.
- `go test ./pkg/lockservice` passed.
- `go test -race ./pkg/lockservice` passed.
- `go vet ./pkg/lockservice` passed.

No 4.2 backport is planned for this PR.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants