Skip to content

fix(lockservice): scope backend create timeout to recovery - #26553

Merged
XuPeng-SH merged 2 commits into
mainfrom
fix/lockservice-backend-create-timeout
Aug 1, 2026
Merged

XuPeng-SH merged 2 commits into
mainfrom
fix/lockservice-backend-create-timeout

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Aug 1, 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:

Fixes #26547

Related: #26475

Nightly regression: https://github.com/matrixorigin/mo-nightly-regression/actions/runs/30649446904/job/91275888648

What this PR does / why we need it:

The failing 1000-thread sysbench run returned 100 lock RPC errors as backend-closed (20502). Incident metrics show the same 88/12 split across two clients in both MORPC auto-create timeouts and lockservice backend-closed errors, with no create-queue full/drop, circuit-breaker trip, pod restart, or OOM. The connection factory was delayed while the CNs were CPU saturated, so the lockservice-wide 500ms backend-create deadline expired for all callers coalesced on those two cold connections.

The direct mechanism is not unique to #26473: the 500ms lockservice setting came from #23435, and a genuinely blocked factory reproduces the 100/100 failure on both the pre-#26473 baseline and the incident MORPC code. #26473 makes completion-at-the-deadline classification deterministic, which can affect the boundary, but a real factory delay beyond 500ms does not require that change.

This PR:

  • keeps the independent 5s local create-queue admission bound on every lockservice transport;
  • limits the 500ms peer-health deadline to active-transaction recovery and service-validation transports, where fast failure is required;
  • lets normal Lock/Unlock, keeper, and control traffic follow their already-bounded caller contexts and the backend's 5s connect timeout;
  • preserves the independent liveness probe in recovery client configs;
  • classifies backend-create timeout separately from generic backend-closed in MORPC and lockservice metrics;
  • adds a low-cardinality distinct-create-event counter alongside the existing per-request impact counter;
  • emits at most one warning per create state and rate-limits the static event to one log per client per minute;
  • updates the RPC Grafana panel to compare affected requests with distinct create events.

Deep-review hardening:

  • the timeout logger retains only one keyed limiter state, bounding future accidental dynamic-key growth;
  • failure-only diagnostic fields are placed after the pre-existing hot client state, preserving mutex/pool field offsets used by every Send;
  • normal traffic is tested for prompt caller cancellation while factory creation remains blocked;
  • wrapped create-timeout errors retain their dedicated metric classification.

The regression tests construct a successful but delayed backend factory. They verify 100 coalesced callers all reproduce 20502 at 500ms, while producing 100 impact counts, one event count, one retained limiter key, and one warning. The lockservice policy test verifies normal traffic succeeds after waiting beyond 500ms, remains caller-cancellable, and recovery traffic still fails fast.

Verification after rebasing onto latest main:

  • focused fan-out race: T=0.5s, B=30s, N=60
  • focused lockservice role/cancellation race: T=1.11s, B=30s, N=27
  • admission-boundary, nil-state timeout, and error-classification race: N=100 each
  • full ./pkg/common/morpc race: passed
  • full ./pkg/lockservice race: passed
  • full non-race MORPC, lockservice, and metric-v2 tests: passed
  • build and vet for all four modified packages: passed
  • hot-path benchmark, clean main vs PR: both 144 B/op and 1 alloc/op; PR 207-212 ns/op vs main 210-211 ns/op
  • dashboard compile-only test: passed; its live-Grafana tests require 127.0.0.1:80 and fail identically on clean HEAD when Grafana is absent

@mergify mergify Bot added kind/bug Something isn't working kind/enhancement labels Aug 1, 2026
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Scope lockservice backend-create timeout to recovery transports

🐞 Bug fix ✨ Enhancement 🧪 Tests ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Limit the 500ms backend-create deadline to recovery/validation lockservice RPC clients.
• Add distinct create-timeout event metrics and rate-limited diagnostics for coalesced callers.
• Update tests and Grafana to validate and visualize timeout impact vs create events.
Diagram

graph TD
  LS["lockservice RPC client"] --> N["Normal RPC clients"] --> MC["morpc client auto-create"]
  LS --> R["Recovery/validation clients"] --> MC
  MC --> E["ErrBackendCreateTimeout"] --> M[("Prometheus metrics")] --> G["Grafana RPC panel"]
  MC --> L["Rate-limited warnings"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Increase the global lockservice backend-create timeout
  • ➕ Simpler change; fewer client configurations to reason about
  • ➕ Reduces false fast-failures during CPU saturation or cold connection creation
  • ➖ Slows recovery/validation failure detection when peers are genuinely gone
  • ➖ Conflates peer health with local congestion; may delay higher-level remediation
2. Warm up connections proactively (background pre-connect)
  • ➕ Avoids latency spikes and coalesced deadline storms on first use
  • ➕ Can reduce request-path sensitivity to CPU saturation
  • ➖ More moving parts (lifecycle management, retries, backoff, shutdown ordering)
  • ➖ May create unnecessary connections for rarely-used peers

Recommendation: Prefer the PR’s scoped-timeout approach: keep fast failure where it matters (recovery/validation) while letting normal lock traffic follow caller contexts and existing connect bounds. The added distinct event metric and rate-limited diagnostics directly improve incident triage without inflating log volume.

Files changed (9) +419 / -34

Enhancement (2) +17 / -0
metrics.goAdd create-timeout event metric and classify create-timeout separately +5/-0

Add create-timeout event metric and classify create-timeout separately

• Extends morpc metrics with a distinct backend-create timeout event counter. Updates RPC error type classification to emit backend_create_timeout instead of folding into backend_closed.

pkg/common/morpc/metrics.go

morpc.goDefine backend auto-create timeout event Prometheus counter and helper +12/-0

Define backend auto-create timeout event Prometheus counter and helper

• Adds a new Prometheus CounterVec for backend_auto_create_timeout_event_total and a helper to retrieve the counter by name, used by morpc metrics initialization.

pkg/util/metric/v2/morpc.go

Bug fix (2) +84 / -30
client.goDeduplicate backend-create timeout diagnostics and add rate-limited logging +47/-14

Deduplicate backend-create timeout diagnostics and add rate-limited logging

• Introduces a diagnostic logger and rate-limited logger to avoid noisy client-wide warnings. Tracks per-request timeout impact while deduplicating per-create-state warnings and adding a distinct event counter for coalesced timeouts.

pkg/common/morpc/client.go

rpc.goApply 500ms backend-create deadline only to recovery/validation transports +37/-16

Apply 500ms backend-create deadline only to recovery/validation transports

• Stops globally applying the 500ms backend-create wait timeout to all lockservice morpc clients. Keeps the 5s create-queue admission bound for all clients, and builds separate configs so recovery/validation clients retain fast failure while normal traffic follows caller contexts.

pkg/lockservice/rpc.go

Tests (3) +310 / -0
client_backend_deadline_regression_test.goRegression test for coalesced callers timing out on late-successful backend create +162/-0

Regression test for coalesced callers timing out on late-successful backend create

• Adds a test backend factory that succeeds only after release, reproducing the 'late create' shape with many coalesced callers. Verifies all callers hit ErrBackendCreateTimeout, with 100 impact counts, 1 event count, and a single rate-limited warning.

pkg/common/morpc/client_backend_deadline_regression_test.go

status_test.goTest coverage for backend_create_timeout error typing +1/-0

Test coverage for backend_create_timeout error typing

• Adds a unit test case ensuring ErrBackendCreateTimeout maps to the backend_create_timeout metric error type.

pkg/common/morpc/status_test.go

rpc_test.goTest lockservice backend-create timeout policy split (normal vs recovery) +147/-0

Test lockservice backend-create timeout policy split (normal vs recovery)

• Adds a blocking backend factory and verifies normal lock traffic is not cut off by the recovery 500ms deadline. Confirms recovery traffic still fails fast with morpc.ErrBackendCreateTimeout when creation blocks.

pkg/lockservice/rpc_test.go

Other (2) +8 / -4
grafana_dashboard_rpc.goGrafana: compare auto-create timeout request impact vs distinct events +7/-4

Grafana: compare auto-create timeout request impact vs distinct events

• Updates the RPC dashboard panel to plot both auto-create timeout request rate and distinct create-event rate, enabling easier identification of coalesced timeout storms.

pkg/util/metric/v2/dashboard/grafana_dashboard_rpc.go

metrics.goRegister new backend auto-create timeout event counter +1/-0

Register new backend auto-create timeout event counter

• Registers the new RPC backend auto-create timeout event counter with the metrics registry so it is exported.

pkg/util/metric/v2/metrics.go

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

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

Deep review completed at 81fdcbf. The policy split matches the production incident path: normal Lock/Unlock, keeper, and control traffic now follow their bounded caller contexts, while active-transaction recovery and service validation retain the 500ms peer-health deadline and all transports retain the independent 5s create-queue bound. MORPC create-state ownership, cancellation, timeout races, event deduplication, metric cardinality, error classification, and config slice isolation were checked without finding a production-reachable correctness, hang, leak, or normal-business regression. Focused race tests passed for MORPC and lockservice; current effective CI checks are successful.

@XuPeng-SH
XuPeng-SH merged commit 0e24dc3 into main Aug 1, 2026
31 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/lockservice-backend-create-timeout branch August 1, 2026 10:44

@aptend aptend 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 the complete diff at d2301bd after the latest main merge. No blocking correctness, concurrency, lifecycle, or observability issues found. Verified the transport-policy split, caller-bound normal traffic, fail-closed recovery/validation behavior, backend-create state ownership and late completion, config slice isolation, per-request/per-create-state metric accounting, bounded rate-limited logging, and constructor/Close cleanup. Focused repeated race tests, full MORPC and lockservice race/non-race suites, metric-v2 tests, affected-package build/vet, and dashboard compile-only validation passed. The live-Grafana dashboard tests require a local Grafana and fail identically on the clean base when it is absent.

XuPeng-SH added a commit that referenced this pull request Aug 2, 2026
## What type of PR is this?

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

## Which issue(s) this PR relates to:

Related to #26551

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

The observed lock RPC deadline in #26551 was fixed directly by #26553,
which
scopes the backend-create timeout to recovery. This follow-up hardens
the test
topology against two independent failure modes exposed during that
investigation:
Unix socket collisions and incomplete cleanup after a callback failure.

This change:

- migrates every lockservice test helper away from
`time.Now().Nanosecond()`
  socket names to an OS-allocated `/tmp/mo-lockservice-*` directory;
- places the allocator and service sockets under that exclusive
directory with
  short deterministic file names;
- installs cleanup ownership before invoking the callback, including
partially
  constructed topologies;
- closes every service, allocator, cluster, and socket directory even if
an
  earlier close fails or the callback panics; and
- adds regressions for cleanup ordering, partial construction, panic
handling,
  directory isolation, and the mainline timeout policy.

Validation:

- `go build ./pkg/lockservice`
- `go vet ./pkg/lockservice`
- `golangci-lint run -c .golangci.yml ./pkg/lockservice/...`
- focused cleanup and socket isolation race tests, 100 repetitions each
- `TestNewTxnLockInRollingRestartCN` under race, 10 repetitions
- `TestLockserviceBackendCreateTimeoutPolicy` under race, 100
repetitions
- `TestAutoCreateDeadlineRejectsLateSuccessfulBackend` under race, 100
repetitions
- full `pkg/lockservice` tests, with and without race detection

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#26553)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26547

Related: matrixorigin#26475

Nightly regression:
https://github.com/matrixorigin/mo-nightly-regression/actions/runs/30649446904/job/91275888648

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

The failing 1000-thread sysbench run returned 100 lock RPC errors as
backend-closed (20502). Incident metrics show the same 88/12 split
across two clients in both MORPC auto-create timeouts and lockservice
backend-closed errors, with no create-queue full/drop, circuit-breaker
trip, pod restart, or OOM. The connection factory was delayed while the
CNs were CPU saturated, so the lockservice-wide 500ms backend-create
deadline expired for all callers coalesced on those two cold
connections.

The direct mechanism is not unique to matrixorigin#26473: the 500ms lockservice
setting came from matrixorigin#23435, and a genuinely blocked factory reproduces the
100/100 failure on both the pre-matrixorigin#26473 baseline and the incident MORPC
code. matrixorigin#26473 makes completion-at-the-deadline classification
deterministic, which can affect the boundary, but a real factory delay
beyond 500ms does not require that change.

This PR:

- keeps the independent 5s local create-queue admission bound on every
lockservice transport;
- limits the 500ms peer-health deadline to active-transaction recovery
and service-validation transports, where fast failure is required;
- lets normal Lock/Unlock, keeper, and control traffic follow their
already-bounded caller contexts and the backend's 5s connect timeout;
- preserves the independent liveness probe in recovery client configs;
- classifies backend-create timeout separately from generic
backend-closed in MORPC and lockservice metrics;
- adds a low-cardinality distinct-create-event counter alongside the
existing per-request impact counter;
- emits at most one warning per create state and rate-limits the static
event to one log per client per minute;
- updates the RPC Grafana panel to compare affected requests with
distinct create events.

Deep-review hardening:

- the timeout logger retains only one keyed limiter state, bounding
future accidental dynamic-key growth;
- failure-only diagnostic fields are placed after the pre-existing hot
client state, preserving mutex/pool field offsets used by every Send;
- normal traffic is tested for prompt caller cancellation while factory
creation remains blocked;
- wrapped create-timeout errors retain their dedicated metric
classification.

The regression tests construct a successful but delayed backend factory.
They verify 100 coalesced callers all reproduce 20502 at 500ms, while
producing 100 impact counts, one event count, one retained limiter key,
and one warning. The lockservice policy test verifies normal traffic
succeeds after waiting beyond 500ms, remains caller-cancellable, and
recovery traffic still fails fast.

Verification after rebasing onto latest main:

- focused fan-out race: T=0.5s, B=30s, N=60
- focused lockservice role/cancellation race: T=1.11s, B=30s, N=27
- admission-boundary, nil-state timeout, and error-classification race:
N=100 each
- full `./pkg/common/morpc` race: passed
- full `./pkg/lockservice` race: passed
- full non-race MORPC, lockservice, and metric-v2 tests: passed
- build and vet for all four modified packages: passed
- hot-path benchmark, clean main vs PR: both 144 B/op and 1 alloc/op; PR
207-212 ns/op vs main 210-211 ns/op
- dashboard compile-only test: passed; its live-Grafana tests require
`127.0.0.1:80` and fail identically on clean HEAD when Grafana is absent
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR relates to:

Related to matrixorigin#26551

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

The observed lock RPC deadline in matrixorigin#26551 was fixed directly by matrixorigin#26553,
which
scopes the backend-create timeout to recovery. This follow-up hardens
the test
topology against two independent failure modes exposed during that
investigation:
Unix socket collisions and incomplete cleanup after a callback failure.

This change:

- migrates every lockservice test helper away from
`time.Now().Nanosecond()`
  socket names to an OS-allocated `/tmp/mo-lockservice-*` directory;
- places the allocator and service sockets under that exclusive
directory with
  short deterministic file names;
- installs cleanup ownership before invoking the callback, including
partially
  constructed topologies;
- closes every service, allocator, cluster, and socket directory even if
an
  earlier close fails or the callback panics; and
- adds regressions for cleanup ordering, partial construction, panic
handling,
  directory isolation, and the mainline timeout policy.

Validation:

- `go build ./pkg/lockservice`
- `go vet ./pkg/lockservice`
- `golangci-lint run -c .golangci.yml ./pkg/lockservice/...`
- focused cleanup and socket isolation race tests, 100 repetitions each
- `TestNewTxnLockInRollingRestartCN` under race, 10 repetitions
- `TestLockserviceBackendCreateTimeoutPolicy` under race, 100
repetitions
- `TestAutoCreateDeadlineRejectsLateSuccessfulBackend` under race, 100
repetitions
- full `pkg/lockservice` tests, with and without race detection

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#26553)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26547

Related: matrixorigin#26475

Nightly regression:
https://github.com/matrixorigin/mo-nightly-regression/actions/runs/30649446904/job/91275888648

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

The failing 1000-thread sysbench run returned 100 lock RPC errors as
backend-closed (20502). Incident metrics show the same 88/12 split
across two clients in both MORPC auto-create timeouts and lockservice
backend-closed errors, with no create-queue full/drop, circuit-breaker
trip, pod restart, or OOM. The connection factory was delayed while the
CNs were CPU saturated, so the lockservice-wide 500ms backend-create
deadline expired for all callers coalesced on those two cold
connections.

The direct mechanism is not unique to matrixorigin#26473: the 500ms lockservice
setting came from matrixorigin#23435, and a genuinely blocked factory reproduces the
100/100 failure on both the pre-matrixorigin#26473 baseline and the incident MORPC
code. matrixorigin#26473 makes completion-at-the-deadline classification
deterministic, which can affect the boundary, but a real factory delay
beyond 500ms does not require that change.

This PR:

- keeps the independent 5s local create-queue admission bound on every
lockservice transport;
- limits the 500ms peer-health deadline to active-transaction recovery
and service-validation transports, where fast failure is required;
- lets normal Lock/Unlock, keeper, and control traffic follow their
already-bounded caller contexts and the backend's 5s connect timeout;
- preserves the independent liveness probe in recovery client configs;
- classifies backend-create timeout separately from generic
backend-closed in MORPC and lockservice metrics;
- adds a low-cardinality distinct-create-event counter alongside the
existing per-request impact counter;
- emits at most one warning per create state and rate-limits the static
event to one log per client per minute;
- updates the RPC Grafana panel to compare affected requests with
distinct create events.

Deep-review hardening:

- the timeout logger retains only one keyed limiter state, bounding
future accidental dynamic-key growth;
- failure-only diagnostic fields are placed after the pre-existing hot
client state, preserving mutex/pool field offsets used by every Send;
- normal traffic is tested for prompt caller cancellation while factory
creation remains blocked;
- wrapped create-timeout errors retain their dedicated metric
classification.

The regression tests construct a successful but delayed backend factory.
They verify 100 coalesced callers all reproduce 20502 at 500ms, while
producing 100 impact counts, one event count, one retained limiter key,
and one warning. The lockservice policy test verifies normal traffic
succeeds after waiting beyond 500ms, remains caller-cancellable, and
recovery traffic still fails fast.

Verification after rebasing onto latest main:

- focused fan-out race: T=0.5s, B=30s, N=60
- focused lockservice role/cancellation race: T=1.11s, B=30s, N=27
- admission-boundary, nil-state timeout, and error-classification race:
N=100 each
- full `./pkg/common/morpc` race: passed
- full `./pkg/lockservice` race: passed
- full non-race MORPC, lockservice, and metric-v2 tests: passed
- build and vet for all four modified packages: passed
- hot-path benchmark, clean main vs PR: both 144 B/op and 1 alloc/op; PR
207-212 ns/op vs main 210-211 ns/op
- dashboard compile-only test: passed; its live-Grafana tests require
`127.0.0.1:80` and fail identically on clean HEAD when Grafana is absent
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR relates to:

Related to matrixorigin#26551

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

The observed lock RPC deadline in matrixorigin#26551 was fixed directly by matrixorigin#26553,
which
scopes the backend-create timeout to recovery. This follow-up hardens
the test
topology against two independent failure modes exposed during that
investigation:
Unix socket collisions and incomplete cleanup after a callback failure.

This change:

- migrates every lockservice test helper away from
`time.Now().Nanosecond()`
  socket names to an OS-allocated `/tmp/mo-lockservice-*` directory;
- places the allocator and service sockets under that exclusive
directory with
  short deterministic file names;
- installs cleanup ownership before invoking the callback, including
partially
  constructed topologies;
- closes every service, allocator, cluster, and socket directory even if
an
  earlier close fails or the callback panics; and
- adds regressions for cleanup ordering, partial construction, panic
handling,
  directory isolation, and the mainline timeout policy.

Validation:

- `go build ./pkg/lockservice`
- `go vet ./pkg/lockservice`
- `golangci-lint run -c .golangci.yml ./pkg/lockservice/...`
- focused cleanup and socket isolation race tests, 100 repetitions each
- `TestNewTxnLockInRollingRestartCN` under race, 10 repetitions
- `TestLockserviceBackendCreateTimeoutPolicy` under race, 100
repetitions
- `TestAutoCreateDeadlineRejectsLateSuccessfulBackend` under race, 100
repetitions
- full `pkg/lockservice` tests, with and without race detection

---------

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…gin#26553)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26547

Related: matrixorigin#26475

Nightly regression:
https://github.com/matrixorigin/mo-nightly-regression/actions/runs/30649446904/job/91275888648

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

The failing 1000-thread sysbench run returned 100 lock RPC errors as
backend-closed (20502). Incident metrics show the same 88/12 split
across two clients in both MORPC auto-create timeouts and lockservice
backend-closed errors, with no create-queue full/drop, circuit-breaker
trip, pod restart, or OOM. The connection factory was delayed while the
CNs were CPU saturated, so the lockservice-wide 500ms backend-create
deadline expired for all callers coalesced on those two cold
connections.

The direct mechanism is not unique to matrixorigin#26473: the 500ms lockservice
setting came from matrixorigin#23435, and a genuinely blocked factory reproduces the
100/100 failure on both the pre-matrixorigin#26473 baseline and the incident MORPC
code. matrixorigin#26473 makes completion-at-the-deadline classification
deterministic, which can affect the boundary, but a real factory delay
beyond 500ms does not require that change.

This PR:

- keeps the independent 5s local create-queue admission bound on every
lockservice transport;
- limits the 500ms peer-health deadline to active-transaction recovery
and service-validation transports, where fast failure is required;
- lets normal Lock/Unlock, keeper, and control traffic follow their
already-bounded caller contexts and the backend's 5s connect timeout;
- preserves the independent liveness probe in recovery client configs;
- classifies backend-create timeout separately from generic
backend-closed in MORPC and lockservice metrics;
- adds a low-cardinality distinct-create-event counter alongside the
existing per-request impact counter;
- emits at most one warning per create state and rate-limits the static
event to one log per client per minute;
- updates the RPC Grafana panel to compare affected requests with
distinct create events.

Deep-review hardening:

- the timeout logger retains only one keyed limiter state, bounding
future accidental dynamic-key growth;
- failure-only diagnostic fields are placed after the pre-existing hot
client state, preserving mutex/pool field offsets used by every Send;
- normal traffic is tested for prompt caller cancellation while factory
creation remains blocked;
- wrapped create-timeout errors retain their dedicated metric
classification.

The regression tests construct a successful but delayed backend factory.
They verify 100 coalesced callers all reproduce 20502 at 500ms, while
producing 100 impact counts, one event count, one retained limiter key,
and one warning. The lockservice policy test verifies normal traffic
succeeds after waiting beyond 500ms, remains caller-cancellable, and
recovery traffic still fails fast.

Verification after rebasing onto latest main:

- focused fan-out race: T=0.5s, B=30s, N=60
- focused lockservice role/cancellation race: T=1.11s, B=30s, N=27
- admission-boundary, nil-state timeout, and error-classification race:
N=100 each
- full `./pkg/common/morpc` race: passed
- full `./pkg/lockservice` race: passed
- full non-race MORPC, lockservice, and metric-v2 tests: passed
- build and vet for all four modified packages: passed
- hot-path benchmark, clean main vs PR: both 144 B/op and 1 alloc/op; PR
207-212 ns/op vs main 210-211 ns/op
- dashboard compile-only test: passed; its live-Grafana tests require
`127.0.0.1:80` and fail identically on clean HEAD when Grafana is absent
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What type of PR is this?

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

## Which issue(s) this PR relates to:

Related to matrixorigin#26551

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

The observed lock RPC deadline in matrixorigin#26551 was fixed directly by matrixorigin#26553,
which
scopes the backend-create timeout to recovery. This follow-up hardens
the test
topology against two independent failure modes exposed during that
investigation:
Unix socket collisions and incomplete cleanup after a callback failure.

This change:

- migrates every lockservice test helper away from
`time.Now().Nanosecond()`
  socket names to an OS-allocated `/tmp/mo-lockservice-*` directory;
- places the allocator and service sockets under that exclusive
directory with
  short deterministic file names;
- installs cleanup ownership before invoking the callback, including
partially
  constructed topologies;
- closes every service, allocator, cluster, and socket directory even if
an
  earlier close fails or the callback panics; and
- adds regressions for cleanup ordering, partial construction, panic
handling,
  directory isolation, and the mainline timeout policy.

Validation:

- `go build ./pkg/lockservice`
- `go vet ./pkg/lockservice`
- `golangci-lint run -c .golangci.yml ./pkg/lockservice/...`
- focused cleanup and socket isolation race tests, 100 repetitions each
- `TestNewTxnLockInRollingRestartCN` under race, 10 repetitions
- `TestLockserviceBackendCreateTimeoutPolicy` under race, 100
repetitions
- `TestAutoCreateDeadlineRejectsLateSuccessfulBackend` under race, 100
repetitions
- full `pkg/lockservice` tests, with and without race detection

---------

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/bug Something isn't working 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] sysbench 1000w read_write 1000t: backend connection closed (20502) 导致测试失败

4 participants