Repository navigation
test(morpc): guard backend pool assertion against idle GC - #27837
Conversation
bafd39f to
2e176d3
Compare
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.
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.
Merge Queue Status
This pull request spent 18 seconds in the queue, including 2 seconds running CI. Required conditions to merge
|
…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
…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
…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
What type of PR is this?
Which issue(s) this PR fixes:
Related to #27835
What this PR does / why we need it:
Root cause
TestGetBackendWithCreateBackendreadlen(c.mu.backends["b1"])aftergetBackendreturned without holdingc.mu. The process-wideclientGCManagercan concurrently invokecloseIdleBackends, which holds the same mutex while compacting and reassigning the backend slice inc.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=1msand the race-enabled test repeated 100 times; the run reported a race inTestGetBackendWithCreateBackendbetweenclient_test.go:1705andclient.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
TestGetBackendWithCreateBackendis the regression case for this issue. Its backend-count assertion now uses the same client mutex asgetBackendandcloseIdleBackends, 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/morpcMORPC_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/morpcGOWORK=off go vet -mod=readonly ./pkg/common/morpcGOWORK=off go build -mod=readonly ./pkg/common/morpcAll 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.