Skip to content

test(lockservice): harden test topology cleanup - #26555

Merged
XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
ck89119:issue-26551-main
Aug 2, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
ck89119:issue-26551-main

Conversation

@ck89119

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

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

@matrix-meow matrix-meow added size/M Denotes a PR that changes [100,499] lines and removed size/S Denotes a PR that changes [10,99] lines labels Aug 1, 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.

Re-reviewed the complete diff at ec6b0db. The previous blockers are closed: cleanup ownership is registered before construction/callback failure points, every constructed service is attempted before allocator/cluster/socket-directory teardown, cleanup errors are joined, and callback panics are preserved. All lockservice timestamp-based Unix socket helpers are now isolated with MkdirTemp; the original backend-create timeout fix remains correctly attributed to #26553.

Unhappy-path audit (Q1/Q2/Q3): no unowned resource, unbounded wait, or skipped later cleanup remains in the changed paths. This is test-only code, so there is no production/non-spill performance cost.

Fresh local verification:

  • focused cleanup/socket/RPC tests: pass
  • the same focused set under -race, count=3: pass
  • full ./pkg/lockservice, count=1: pass (102.5s)

Approving this head.

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

mergify Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-02 00:19 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-08-02 00:19 UTC · at ec6b0dbea44e28dfb06a64dacee051cd2576187a

This pull request spent 9 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/entrypoint.yaml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@mergify mergify Bot added dequeued and removed queued labels Aug 2, 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.

Revalidated the merge-updated head 500a838. This commit is a clean merge of main into the previously approved ec6b0db head: the current PR diff is still exactly the same four lockservice test files, and there is no merge delta at all in those PR-owned files. The cleanup ownership/order, panic preservation, partial-construction handling, and MkdirTemp socket isolation therefore remain unchanged.

Fresh focused cleanup/socket/RPC tests passed at count=3 against the merged dependencies. Approval stands for this exact head; the newly triggered required CI jobs are still running.

@ck89119
ck89119 deleted the issue-26551-main branch August 2, 2026 05:06
XuPeng-SH pushed a commit that referenced this pull request Aug 3, 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 fixes:

Fixes #26575

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

### Root cause

Lockservice active-transaction recovery intentionally uses a separate
MORPC
client with a 500ms backend-create budget. The failing CI log shows that
cold
connection timing out after 500.241548ms. Production correctly treats
that
observation as indeterminate: it retains the transaction and retries
during a
later timeout scan. `TestCheckTxnTimeout` instead required the
transaction to be
removed by one scan, so scheduler delay in a valid recovery path failed
the
test.

At the failing commit, that assertion also exited the topology callback
before
the service and allocator cleanup statements. Their RPC goroutines
remained
active and caused the later `TestIssue5176` and
`TestUnlockInRollingRestartCN` leak reports; the latter test's log
contains the
previous test's service ID. Main has since merged #26555, which installs
the
topology cleanup before the callback and closes it from a defer. This PR
does
not duplicate that already-merged cleanup fix.

### Changes

- Make `TestCheckTxnTimeout` assert the production contract: an
indeterminate
scan may retain the transaction, but subsequent scans must eventually
remove
  it after authoritative inactive and cannot-commit fence results.
- Exercise the exact observed `morpc.ErrBackendCreateTimeout` in the
existing
  deterministic error-then-confirmed-inactive unit test.

The 500ms recovery policy remains unchanged. There are no
production-code,
API, wire-format, or performance changes.

### Verification

Environment: Go 1.26.4, Darwin/arm64, controlled MatrixOne CGo test
wrapper.

- Original three tests in order, non-race, `-count=10`: pass
- `TestValidTxnCheckErrorThenConfirmedInactive`, non-race, `-count=100`:
pass
- Adaptive focused race stress (30s budget per test):
  - `TestCheckTxnTimeout`: T=1.16s, N=25
  - `TestValidTxnCheckErrorThenConfirmedInactive`: T=0s, N=100
  - `TestIssue5176`: T=0.09s, N=100
  - `TestUnlockInRollingRestartCN`: T=2.08s, N=14
- Full `./pkg/lockservice`, non-race: pass (113.574s)
- Full `./pkg/lockservice`, race: pass (121.847s)
- `go list`, `go build`, and `go vet` for `./pkg/lockservice`: pass

BVT is not applicable because the affected contract is an internal Go
recovery
scanner and test-topology lifecycle, with no SQL-visible behavior.

### Residual risk

The test retains its existing 10s outer bound and still fails if
recovery never
obtains an authoritative result. It only permits the transient
first-scan
timeout that production explicitly handles by retrying.

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
## 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
…in#26587)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26575

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

### Root cause

Lockservice active-transaction recovery intentionally uses a separate
MORPC
client with a 500ms backend-create budget. The failing CI log shows that
cold
connection timing out after 500.241548ms. Production correctly treats
that
observation as indeterminate: it retains the transaction and retries
during a
later timeout scan. `TestCheckTxnTimeout` instead required the
transaction to be
removed by one scan, so scheduler delay in a valid recovery path failed
the
test.

At the failing commit, that assertion also exited the topology callback
before
the service and allocator cleanup statements. Their RPC goroutines
remained
active and caused the later `TestIssue5176` and
`TestUnlockInRollingRestartCN` leak reports; the latter test's log
contains the
previous test's service ID. Main has since merged matrixorigin#26555, which installs
the
topology cleanup before the callback and closes it from a defer. This PR
does
not duplicate that already-merged cleanup fix.

### Changes

- Make `TestCheckTxnTimeout` assert the production contract: an
indeterminate
scan may retain the transaction, but subsequent scans must eventually
remove
  it after authoritative inactive and cannot-commit fence results.
- Exercise the exact observed `morpc.ErrBackendCreateTimeout` in the
existing
  deterministic error-then-confirmed-inactive unit test.

The 500ms recovery policy remains unchanged. There are no
production-code,
API, wire-format, or performance changes.

### Verification

Environment: Go 1.26.4, Darwin/arm64, controlled MatrixOne CGo test
wrapper.

- Original three tests in order, non-race, `-count=10`: pass
- `TestValidTxnCheckErrorThenConfirmedInactive`, non-race, `-count=100`:
pass
- Adaptive focused race stress (30s budget per test):
  - `TestCheckTxnTimeout`: T=1.16s, N=25
  - `TestValidTxnCheckErrorThenConfirmedInactive`: T=0s, N=100
  - `TestIssue5176`: T=0.09s, N=100
  - `TestUnlockInRollingRestartCN`: T=2.08s, N=14
- Full `./pkg/lockservice`, non-race: pass (113.574s)
- Full `./pkg/lockservice`, race: pass (121.847s)
- `go list`, `go build`, and `go vet` for `./pkg/lockservice`: pass

BVT is not applicable because the affected contract is an internal Go
recovery
scanner and test-topology lifecycle, with no SQL-visible behavior.

### Residual risk

The test retains its existing 10s outer bound and still fails if
recovery never
obtains an authoritative result. It only permits the transient
first-scan
timeout that production explicitly handles by retrying.

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
## 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
…in#26587)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26575

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

### Root cause

Lockservice active-transaction recovery intentionally uses a separate
MORPC
client with a 500ms backend-create budget. The failing CI log shows that
cold
connection timing out after 500.241548ms. Production correctly treats
that
observation as indeterminate: it retains the transaction and retries
during a
later timeout scan. `TestCheckTxnTimeout` instead required the
transaction to be
removed by one scan, so scheduler delay in a valid recovery path failed
the
test.

At the failing commit, that assertion also exited the topology callback
before
the service and allocator cleanup statements. Their RPC goroutines
remained
active and caused the later `TestIssue5176` and
`TestUnlockInRollingRestartCN` leak reports; the latter test's log
contains the
previous test's service ID. Main has since merged matrixorigin#26555, which installs
the
topology cleanup before the callback and closes it from a defer. This PR
does
not duplicate that already-merged cleanup fix.

### Changes

- Make `TestCheckTxnTimeout` assert the production contract: an
indeterminate
scan may retain the transaction, but subsequent scans must eventually
remove
  it after authoritative inactive and cannot-commit fence results.
- Exercise the exact observed `morpc.ErrBackendCreateTimeout` in the
existing
  deterministic error-then-confirmed-inactive unit test.

The 500ms recovery policy remains unchanged. There are no
production-code,
API, wire-format, or performance changes.

### Verification

Environment: Go 1.26.4, Darwin/arm64, controlled MatrixOne CGo test
wrapper.

- Original three tests in order, non-race, `-count=10`: pass
- `TestValidTxnCheckErrorThenConfirmedInactive`, non-race, `-count=100`:
pass
- Adaptive focused race stress (30s budget per test):
  - `TestCheckTxnTimeout`: T=1.16s, N=25
  - `TestValidTxnCheckErrorThenConfirmedInactive`: T=0s, N=100
  - `TestIssue5176`: T=0.09s, N=100
  - `TestUnlockInRollingRestartCN`: T=2.08s, N=14
- Full `./pkg/lockservice`, non-race: pass (113.574s)
- Full `./pkg/lockservice`, race: pass (121.847s)
- `go list`, `go build`, and `go vet` for `./pkg/lockservice`: pass

BVT is not applicable because the affected contract is an internal Go
recovery
scanner and test-topology lifecycle, with no SQL-visible behavior.

### Residual risk

The test retains its existing 10s outer bound and still fails if
recovery never
obtains an authoritative result. It only permits the transient
first-scan
timeout that production explicitly handles by retrying.

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
## 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
…in#26587)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#26575

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

### Root cause

Lockservice active-transaction recovery intentionally uses a separate
MORPC
client with a 500ms backend-create budget. The failing CI log shows that
cold
connection timing out after 500.241548ms. Production correctly treats
that
observation as indeterminate: it retains the transaction and retries
during a
later timeout scan. `TestCheckTxnTimeout` instead required the
transaction to be
removed by one scan, so scheduler delay in a valid recovery path failed
the
test.

At the failing commit, that assertion also exited the topology callback
before
the service and allocator cleanup statements. Their RPC goroutines
remained
active and caused the later `TestIssue5176` and
`TestUnlockInRollingRestartCN` leak reports; the latter test's log
contains the
previous test's service ID. Main has since merged matrixorigin#26555, which installs
the
topology cleanup before the callback and closes it from a defer. This PR
does
not duplicate that already-merged cleanup fix.

### Changes

- Make `TestCheckTxnTimeout` assert the production contract: an
indeterminate
scan may retain the transaction, but subsequent scans must eventually
remove
  it after authoritative inactive and cannot-commit fence results.
- Exercise the exact observed `morpc.ErrBackendCreateTimeout` in the
existing
  deterministic error-then-confirmed-inactive unit test.

The 500ms recovery policy remains unchanged. There are no
production-code,
API, wire-format, or performance changes.

### Verification

Environment: Go 1.26.4, Darwin/arm64, controlled MatrixOne CGo test
wrapper.

- Original three tests in order, non-race, `-count=10`: pass
- `TestValidTxnCheckErrorThenConfirmedInactive`, non-race, `-count=100`:
pass
- Adaptive focused race stress (30s budget per test):
  - `TestCheckTxnTimeout`: T=1.16s, N=25
  - `TestValidTxnCheckErrorThenConfirmedInactive`: T=0s, N=100
  - `TestIssue5176`: T=0.09s, N=100
  - `TestUnlockInRollingRestartCN`: T=2.08s, N=14
- Full `./pkg/lockservice`, non-race: pass (113.574s)
- Full `./pkg/lockservice`, race: pass (121.847s)
- `go list`, `go build`, and `go vet` for `./pkg/lockservice`: pass

BVT is not applicable because the affected contract is an internal Go
recovery
scanner and test-topology lifecycle, with no SQL-visible behavior.

### Residual risk

The test retains its existing 10s outer bound and still fails if
recovery never
obtains an authoritative result. It only permits the transient
first-scan
timeout that production explicitly handles by retrying.

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

This branch was previously deployed

1 inactive deployment
ci — 500a8382 Deployed Aug 2, 2026 by XuPeng-SH via Matrixone Utils CI / Coverage #44049
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/test-ci 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