Repository navigation
fix(morpc): preserve slow responses after probe timeout - #26903
mergify[bot] merged 2 commits into
Conversation
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
This pull request spent 50 minutes 14 seconds in the queue, including 49 minutes 37 seconds running CI. Required conditions to merge
|
## 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>
…#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
…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>
…#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
…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>
…#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
…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>
What type of PR is this?
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:
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
mainbecause the timed-out probe leaves the backend admissible and then resets it.
go test -count=30for the focused liveness/generation tests.go test -race -count=100 -run '^TestTimedOutLivenessProbePreservesSlowDataResponse$' ./pkg/common/morpcgo test -race -count=1 ./pkg/common/morpcgo 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/...