Skip to content

fix(morpc): terminate pending work during backend and stream close - #26004

Merged
XuPeng-SH merged 2 commits into
mainfrom
fix/morpc-close-liveness-25943-25945
Jul 22, 2026
Merged

XuPeng-SH merged 2 commits into
mainfrom
fix/morpc-close-liveness-25943-25945

Conversation

@aptend

@aptend aptend commented Jul 22, 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 #25943
Fixes #25945

What this PR does / why we need it:

  • cancels a stream before waiting for its lock, so a full receive channel cannot block Stream.Close(false)
  • gives each stream an independent handle, receive channel, and cancellation context instead of reusing externally visible stream objects
  • stops backend I/O and closes the transport before failing all response-waiting Futures with backendClosed
  • releases the backend map mutex before taking backend state locks during stream removal
  • adds deterministic close, lock-order, generation-isolation, and race regressions

Testing

  • make thirdparties
  • mo-cgo-test -race -count=20 focused MORPC close regressions
  • mo-cgo-test ./pkg/common/morpc
  • mo-cgo-test -race ./pkg/common/morpc
  • go build ./pkg/common/morpc
  • go vet ./pkg/common/morpc
  • mo-cgo-test ./pkg/cnservice/cnclient

@aptend
aptend requested a review from XuPeng-SH as a code owner July 22, 2026 03:32
@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 exact head 78ab12de83c34e483a4624d277b50534d16ec95d; no blocking correctness or liveness issue found.

I traced the complete backend/stream/future ownership, lock ordering, wait-for graph, and reuse generation boundary:

  • Stream.Close(false) cancels the stream-local delivery context before acquiring the exclusive stream lock, so a response blocked on a full receive channel releases its read lock and close can drain/terminate it;
  • stream unregister now happens after releasing s.mu, and backend removal releases rb.mu before taking stateMu through Unlock, removing both relevant ABBA edges;
  • stream objects/channels/contexts are no longer pooled or externally reused, so an old handle cannot close or consume a later stream generation;
  • backend close stops the write loop, disconnects transport, waits for the read loop, then fails response-waiting futures with backendClosed before deleting tracking entries; response and close cannot both terminally notify a Future;
  • queued writes, stream receive channels, and tracking maps have fixed capacity or explicit removal paths; no new unbounded retention was introduced.

Q1: one effective cleanup owner remains on success, error, repeated close, and finalizer paths. Q2: every changed channel/lock wait has a cancellation or transport-close termination edge. Q3: removal of the stream pool eliminates the backend↔pooled-stream retention cycle and all changed accumulations remain bounded.

Validation:

  • git diff --check origin/main...HEAD
  • focused close/lock-order/generation tests under -race -count=50
  • full go test -race -count=1 ./pkg/common/morpc
  • go test ./pkg/cnservice/cnclient
  • clean merge with current origin/main, followed by fresh MORPC race and cnclient tests
  • required CI is green, including UT, SCA, CodeQL, multi-CN/proxy BVT, coverage, and Summary

@mergify mergify Bot added the queued label Jul 22, 2026
@mergify

mergify Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-22 04:53 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-22 05:12 UTC · at 7dc63de9d1fbbdf0384268853ba79ea5e0d0ea4d

This pull request spent 18 minutes 47 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of: [🛡 GitHub branch protection]
    • 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)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • 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)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection] (documentation)
  • github-review-decision = APPROVED [🛡 GitHub branch protection] (documentation)

Reason

Pull request #26004 has been merged manually at e917fbf

Hint

You were too fast!

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

  • Requeue this pull request

VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…atrixorigin#26004)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#25943
Fixes matrixorigin#25945

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

- cancels a stream before waiting for its lock, so a full receive
channel cannot block Stream.Close(false)
- gives each stream an independent handle, receive channel, and
cancellation context instead of reusing externally visible stream
objects
- stops backend I/O and closes the transport before failing all
response-waiting Futures with backendClosed
- releases the backend map mutex before taking backend state locks
during stream removal
- adds deterministic close, lock-order, generation-isolation, and race
regressions

## Testing

- make thirdparties
- mo-cgo-test -race -count=20 focused MORPC close regressions
- mo-cgo-test ./pkg/common/morpc
- mo-cgo-test -race ./pkg/common/morpc
- go build ./pkg/common/morpc
- go vet ./pkg/common/morpc
- mo-cgo-test ./pkg/cnservice/cnclient

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
…atrixorigin#26004)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#25943
Fixes matrixorigin#25945

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

- cancels a stream before waiting for its lock, so a full receive
channel cannot block Stream.Close(false)
- gives each stream an independent handle, receive channel, and
cancellation context instead of reusing externally visible stream
objects
- stops backend I/O and closes the transport before failing all
response-waiting Futures with backendClosed
- releases the backend map mutex before taking backend state locks
during stream removal
- adds deterministic close, lock-order, generation-isolation, and race
regressions

## Testing

- make thirdparties
- mo-cgo-test -race -count=20 focused MORPC close regressions
- mo-cgo-test ./pkg/common/morpc
- mo-cgo-test -race ./pkg/common/morpc
- go build ./pkg/common/morpc
- go vet ./pkg/common/morpc
- mo-cgo-test ./pkg/cnservice/cnclient

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
…atrixorigin#26004)

## What type of PR is this?

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

## Which issue(s) this PR fixes:

Fixes matrixorigin#25943
Fixes matrixorigin#25945

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

- cancels a stream before waiting for its lock, so a full receive
channel cannot block Stream.Close(false)
- gives each stream an independent handle, receive channel, and
cancellation context instead of reusing externally visible stream
objects
- stops backend I/O and closes the transport before failing all
response-waiting Futures with backendClosed
- releases the backend map mutex before taking backend state locks
during stream removal
- adds deterministic close, lock-order, generation-isolation, and race
regressions

## Testing

- make thirdparties
- mo-cgo-test -race -count=20 focused MORPC close regressions
- mo-cgo-test ./pkg/common/morpc
- mo-cgo-test -race ./pkg/common/morpc
- go build ./pkg/common/morpc
- go vet ./pkg/common/morpc
- mo-cgo-test ./pkg/cnservice/cnclient

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

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: closing a morpc backend leaves response-waiting Futures blocked [Bug]: morpc Stream.Close(false) deadlocks behind a full receive channel

3 participants