Skip to content

fix(morpc): isolate backend factory options - #26567

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

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

Conversation

@gouhongshen

@gouhongshen gouhongshen 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 #26562

What this PR does / why we need it:

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.

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

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

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

mergify Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

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

This pull request spent 13 seconds in the queue, including 1 second 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 Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • 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

@mergify
mergify Bot merged commit 986e179 into matrixorigin:main Aug 1, 2026
68 of 88 checks passed
@mergify mergify Bot removed the queued label Aug 1, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
### 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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
### 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
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
### 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

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 size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: concurrent morpc backend creation races on factory options

3 participants