Skip to content

test(morpc): guard backend pool assertion against idle GC - #27837

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-27835-f093feb0
Aug 29, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
gouhongshen:agent/issue-27835-f093feb0

Conversation

@gouhongshen

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:

Related to #27835

What this PR does / why we need it:

Root cause

TestGetBackendWithCreateBackend read len(c.mu.backends["b1"]) after getBackend returned without holding c.mu. The process-wide clientGCManager can concurrently invoke closeIdleBackends, which holds the same mutex while compacting and reassigning the backend slice in c.mu.backends. The test's unsynchronized map read therefore raced with a legitimate idle-GC lifecycle update.

The original race was reproduced before this change with MORPC_GC_IDLE_INTERVAL=1ms and the race-enabled test repeated 100 times; the run reported a race in TestGetBackendWithCreateBackend between client_test.go:1705 and client.go:1873.

Change

Read the backend count while holding c.mu, copy it to a local scalar, then release the mutex before performing the assertion. This preserves the existing backend-creation oracle and changes no production behavior.

Issue-to-test proof

The existing TestGetBackendWithCreateBackend is the regression case for this issue. Its backend-count assertion now uses the same client mutex as getBackend and closeIdleBackends, so the exact reported map access is synchronized while the assertion still requires exactly one created backend.

BVT is not applicable: this is an internal MORPC unit-test synchronization issue with no SQL, wire-protocol, or public API behavior change.

Validation

  • .agents/skills/mo-dev/scripts/mo-cgo-test -list '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc
  • .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc
  • MORPC_GC_IDLE_INTERVAL=1ms .agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=100 -timeout=120s -run '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1 -timeout=300s ./pkg/common/morpc
  • GOWORK=off go vet -mod=readonly ./pkg/common/morpc
  • GOWORK=off go build -mod=readonly ./pkg/common/morpc

All commands passed after the change; the focused race stress completed all 100 iterations and the complete MORPC race suite passed.

Scope and residual risk

The committed diff contains only the four-line synchronization adjustment in pkg/common/morpc/client_test.go. The process-wide idle-GC scheduler and asynchronous backend creation behavior remain unchanged; no known residual race remains for the reported assertion.

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

Reviewed exact head 2e176d38d4adc51bca6b4315d586834957b31651. The change closes the reported test-only race by reading the backend map and slice under the same client mutex used by idle GC, then releases the mutex before assertion. The oracle remains exact (backendCount == 1), no production path changes, and Q1-Q3 are unchanged. Exact-head CI is green; the author also supplied focused 100x race stress and the full MORPC race package run. I found no correctness, liveness, cleanup, boundedness, performance, or test-quality blocker.

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

mergify Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-29 07:19 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-08-29 07:19 UTC · at 2e176d38d4adc51bca6b4315d586834957b31651 · squash

This pull request spent 18 seconds in the queue, including 2 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 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
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit 2d6191f into matrixorigin:main Aug 29, 2026
41 of 47 checks passed
@mergify mergify Bot removed the queued label Aug 29, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#27837)

### Root cause

`TestGetBackendWithCreateBackend` read `len(c.mu.backends["b1"])` after `getBackend` returned without holding `c.mu`. The process-wide `clientGCManager` can concurrently invoke `closeIdleBackends`, which holds the same mutex while compacting and reassigning the backend slice in `c.mu.backends`. The test's unsynchronized map read therefore raced with a legitimate idle-GC lifecycle update.

The original race was reproduced before this change with `MORPC_GC_IDLE_INTERVAL=1ms` and the race-enabled test repeated 100 times; the run reported a race in `TestGetBackendWithCreateBackend` between `client_test.go:1705` and `client.go:1873`.

### Change

Read the backend count while holding `c.mu`, copy it to a local scalar, then release the mutex before performing the assertion. This preserves the existing backend-creation oracle and changes no production behavior.

### Issue-to-test proof

The existing `TestGetBackendWithCreateBackend` is the regression case for this issue. Its backend-count assertion now uses the same client mutex as `getBackend` and `closeIdleBackends`, so the exact reported map access is synchronized while the assertion still requires exactly one created backend.

BVT is not applicable: this is an internal MORPC unit-test synchronization issue with no SQL, wire-protocol, or public API behavior change.

### Validation

- `.agents/skills/mo-dev/scripts/mo-cgo-test -list '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc`
- `MORPC_GC_IDLE_INTERVAL=1ms .agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=100 -timeout=120s -run '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1 -timeout=300s ./pkg/common/morpc`
- `GOWORK=off go vet -mod=readonly ./pkg/common/morpc`
- `GOWORK=off go build -mod=readonly ./pkg/common/morpc`

All commands passed after the change; the focused race stress completed all 100 iterations and the complete MORPC race suite passed.

### Scope and residual risk

The committed diff contains only the four-line synchronization adjustment in `pkg/common/morpc/client_test.go`. The process-wide idle-GC scheduler and asynchronous backend creation behavior remain unchanged; no known residual race remains for the reported assertion.

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

### Root cause

`TestGetBackendWithCreateBackend` read `len(c.mu.backends["b1"])` after `getBackend` returned without holding `c.mu`. The process-wide `clientGCManager` can concurrently invoke `closeIdleBackends`, which holds the same mutex while compacting and reassigning the backend slice in `c.mu.backends`. The test's unsynchronized map read therefore raced with a legitimate idle-GC lifecycle update.

The original race was reproduced before this change with `MORPC_GC_IDLE_INTERVAL=1ms` and the race-enabled test repeated 100 times; the run reported a race in `TestGetBackendWithCreateBackend` between `client_test.go:1705` and `client.go:1873`.

### Change

Read the backend count while holding `c.mu`, copy it to a local scalar, then release the mutex before performing the assertion. This preserves the existing backend-creation oracle and changes no production behavior.

### Issue-to-test proof

The existing `TestGetBackendWithCreateBackend` is the regression case for this issue. Its backend-count assertion now uses the same client mutex as `getBackend` and `closeIdleBackends`, so the exact reported map access is synchronized while the assertion still requires exactly one created backend.

BVT is not applicable: this is an internal MORPC unit-test synchronization issue with no SQL, wire-protocol, or public API behavior change.

### Validation

- `.agents/skills/mo-dev/scripts/mo-cgo-test -list '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc`
- `MORPC_GC_IDLE_INTERVAL=1ms .agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=100 -timeout=120s -run '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1 -timeout=300s ./pkg/common/morpc`
- `GOWORK=off go vet -mod=readonly ./pkg/common/morpc`
- `GOWORK=off go build -mod=readonly ./pkg/common/morpc`

All commands passed after the change; the focused race stress completed all 100 iterations and the complete MORPC race suite passed.

### Scope and residual risk

The committed diff contains only the four-line synchronization adjustment in `pkg/common/morpc/client_test.go`. The process-wide idle-GC scheduler and asynchronous backend creation behavior remain unchanged; no known residual race remains for the reported assertion.

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

### Root cause

`TestGetBackendWithCreateBackend` read `len(c.mu.backends["b1"])` after `getBackend` returned without holding `c.mu`. The process-wide `clientGCManager` can concurrently invoke `closeIdleBackends`, which holds the same mutex while compacting and reassigning the backend slice in `c.mu.backends`. The test's unsynchronized map read therefore raced with a legitimate idle-GC lifecycle update.

The original race was reproduced before this change with `MORPC_GC_IDLE_INTERVAL=1ms` and the race-enabled test repeated 100 times; the run reported a race in `TestGetBackendWithCreateBackend` between `client_test.go:1705` and `client.go:1873`.

### Change

Read the backend count while holding `c.mu`, copy it to a local scalar, then release the mutex before performing the assertion. This preserves the existing backend-creation oracle and changes no production behavior.

### Issue-to-test proof

The existing `TestGetBackendWithCreateBackend` is the regression case for this issue. Its backend-count assertion now uses the same client mutex as `getBackend` and `closeIdleBackends`, so the exact reported map access is synchronized while the assertion still requires exactly one created backend.

BVT is not applicable: this is an internal MORPC unit-test synchronization issue with no SQL, wire-protocol, or public API behavior change.

### Validation

- `.agents/skills/mo-dev/scripts/mo-cgo-test -list '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc`
- `MORPC_GC_IDLE_INTERVAL=1ms .agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=100 -timeout=120s -run '^TestGetBackendWithCreateBackend$' ./pkg/common/morpc`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -v -count=1 -timeout=300s ./pkg/common/morpc`
- `GOWORK=off go vet -mod=readonly ./pkg/common/morpc`
- `GOWORK=off go build -mod=readonly ./pkg/common/morpc`

All commands passed after the change; the focused race stress completed all 100 iterations and the complete MORPC race suite passed.

### Scope and residual risk

The committed diff contains only the four-line synchronization adjustment in `pkg/common/morpc/client_test.go`. The process-wide idle-GC scheduler and asynchronous backend creation behavior remain unchanged; no known residual race remains for the reported assertion.

Approved by: @XuPeng-SH

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/test-ci size/XS Denotes a PR that changes [1, 9] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants