Repository navigation
fix(morpc): isolate backend factory options - #26567
Conversation
8d5310b to
2e28a1b
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.
Deep-reviewed at 2e28a1b.
The fix gives every Create call an owned options backing array, preserving default-before-extra ordering and override semantics without adding locks or changing backend lifecycle/error behavior. The regression test deterministically overlaps two calls and verifies option isolation. Ownership, wait-for, failure-path, compatibility, and performance audits found no blocker; the added allocation is bounded by the small option count and occurs only during backend creation.
Validation:
- go build / go vet ./pkg/common/morpc
- focused regression test
- focused regression test with -race -count=100
- full pkg/common/morpc tests, normal and -race
- original downstream reproducer TestIssue26087ConcurrentDataBranchQuota with -race
- current PR checks green/skipped as expected
Merge Queue Status
This pull request spent 13 seconds in the queue, including 1 second running CI. Required conditions to merge
|
### Root cause `goettyBasedBackendFactory.Create` appended per-call backend options directly to the factory's `options` slice. When that slice had spare capacity, concurrent calls reused and wrote the same backing-array slots. Parallel backend-create workers made those writes concurrent, causing both a Go data race and cross-call option contamination. ### Changes - Allocate one option slice owned by each `Create` call. - Preserve the existing ordering of factory defaults followed by per-call options. - Add a deterministic concurrency regression test that gives the factory option slice spare capacity, synchronizes two creates before either consumes its per-call option, and verifies that both backends retain their own buffer size. ### Tests - `go build -mod=readonly ./pkg/common/morpc` - `go vet -mod=readonly ./pkg/common/morpc` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/common/morpc` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -timeout=180s -run '^TestGoettyBasedBackendFactoryConcurrentCreateOptions$' ./pkg/common/morpc` (`T=0.03s`, `B=30s`, adaptive `N=100`) - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s ./pkg/common/morpc` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s -run '^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues` (`T=31.27s`, `B=30s`, adaptive `N=1`) ### Residual risks Each backend creation now deliberately allocates a short-lived option slice sized to the combined factory and per-call options. This keeps option ownership local without adding locks or serializing connection creation. No API, wire-format, or configuration behavior changes. Approved by: @XuPeng-SH
### Root cause `goettyBasedBackendFactory.Create` appended per-call backend options directly to the factory's `options` slice. When that slice had spare capacity, concurrent calls reused and wrote the same backing-array slots. Parallel backend-create workers made those writes concurrent, causing both a Go data race and cross-call option contamination. ### Changes - Allocate one option slice owned by each `Create` call. - Preserve the existing ordering of factory defaults followed by per-call options. - Add a deterministic concurrency regression test that gives the factory option slice spare capacity, synchronizes two creates before either consumes its per-call option, and verifies that both backends retain their own buffer size. ### Tests - `go build -mod=readonly ./pkg/common/morpc` - `go vet -mod=readonly ./pkg/common/morpc` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/common/morpc` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -timeout=180s -run '^TestGoettyBasedBackendFactoryConcurrentCreateOptions$' ./pkg/common/morpc` (`T=0.03s`, `B=30s`, adaptive `N=100`) - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s ./pkg/common/morpc` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s -run '^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues` (`T=31.27s`, `B=30s`, adaptive `N=1`) ### Residual risks Each backend creation now deliberately allocates a short-lived option slice sized to the combined factory and per-call options. This keeps option ownership local without adding locks or serializing connection creation. No API, wire-format, or configuration behavior changes. Approved by: @XuPeng-SH
### Root cause `goettyBasedBackendFactory.Create` appended per-call backend options directly to the factory's `options` slice. When that slice had spare capacity, concurrent calls reused and wrote the same backing-array slots. Parallel backend-create workers made those writes concurrent, causing both a Go data race and cross-call option contamination. ### Changes - Allocate one option slice owned by each `Create` call. - Preserve the existing ordering of factory defaults followed by per-call options. - Add a deterministic concurrency regression test that gives the factory option slice spare capacity, synchronizes two creates before either consumes its per-call option, and verifies that both backends retain their own buffer size. ### Tests - `go build -mod=readonly ./pkg/common/morpc` - `go vet -mod=readonly ./pkg/common/morpc` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/common/morpc` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -timeout=180s -run '^TestGoettyBasedBackendFactoryConcurrentCreateOptions$' ./pkg/common/morpc` (`T=0.03s`, `B=30s`, adaptive `N=100`) - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s ./pkg/common/morpc` - `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s -run '^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues` (`T=31.27s`, `B=30s`, adaptive `N=1`) ### Residual risks Each backend creation now deliberately allocates a short-lived option slice sized to the combined factory and per-call options. This keeps option ownership local without adding locks or serializing connection creation. No API, wire-format, or configuration behavior changes. Approved by: @XuPeng-SH
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #26562
What this PR does / why we need it:
Root cause
goettyBasedBackendFactory.Createappended per-call backend options directly to the factory'soptionsslice. When that slice had spare capacity, concurrent calls reused and wrote the same backing-array slots. Parallel backend-create workers made those writes concurrent, causing both a Go data race and cross-call option contamination.Changes
Createcall.Tests
go build -mod=readonly ./pkg/common/morpcgo vet -mod=readonly ./pkg/common/morpc.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/common/morpc.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -timeout=180s -run '^TestGoettyBasedBackendFactoryConcurrentCreateOptions$' ./pkg/common/morpc(T=0.03s,B=30s, adaptiveN=100).agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s ./pkg/common/morpc.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=600s -run '^TestIssue26087ConcurrentDataBranchQuota$' ./pkg/tests/issues(T=31.27s,B=30s, adaptiveN=1)Residual risks
Each backend creation now deliberately allocates a short-lived option slice sized to the combined factory and per-call options. This keeps option ownership local without adding locks or serializing connection creation. No API, wire-format, or configuration behavior changes.