Skip to content

fix: wait for remote receivers on empty dispatch - #25688

Merged
XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
XuPeng-SH:fix/remote-dispatch-empty-input-registration
Jul 13, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
XuPeng-SH:fix/remote-dispatch-empty-input-registration

Conversation

@XuPeng-SH

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 #25687

What this PR does / why we need it:

A remote dispatch currently waits for receiver attachment only when a data batch reaches its send function. If the child produces no batches, Dispatch.Call returns ExecStop immediately. An early RemoteDispatchNotRegistered response can then outlive the producer: cleanup removes the newly published UUID before the client's 200 ms retry, and all later retries fail until the 30-second timeout.

This PR restores the remote-dispatch lifecycle invariant at the producer boundary: successful terminal completion waits for all remote receivers even when the input is empty. It reuses the existing receiver barrier, context cancellation, and 30-second upper bound.

The production change is intentionally limited to the zero-batch remote path:

  • non-empty dispatch is unchanged;
  • local-only dispatch is unchanged;
  • an already attached empty dispatch adds only two boolean checks;
  • a racing registration waits for the existing notify retry instead of failing after 30 seconds;
  • cancellation and unreachable receivers return through the existing bounded error paths;
  • no protocol, lock, goroutine, retry interval, or retained state is added.

The regression tests cover direct empty-input attachment, cancellation-cause propagation, and the exact end-to-end interleaving where the first notify misses registration, the producer registers and becomes empty, and the retry must attach before terminal cleanup. The direct test was also run with the production fix removed and failed immediately, proving that it detects the original bug.

Testing

  • make -j12
  • make dev-build
  • go test ./pkg/sql/colexec/dispatch
  • go test ./pkg/sql/compile
  • go test -race for the empty-dispatch tests
  • go test -race for TestRemoteNotifyRetryAttachesToEmptyDispatchBeforeCompletion
  • go vet ./pkg/sql/colexec/dispatch ./pkg/sql/compile
  • go vet with molint for both affected packages
  • golangci-lint run -c .golangci.yml ./pkg/sql/colexec/dispatch ./pkg/sql/compile
  • Multi-CN Docker reproduction with 5M, 4M, and 1M-row tables: expected result 499999
    • concurrency 8: 200/200 passed; unfixed code failed 4/200
    • concurrency 16: 100/100 passed

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner July 13, 2026 16:05
@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 →

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 8ff7e4f. No blocking issues found. The zero-batch remote path reuses the existing receiver-registration barrier and preserves the Call/Reset lifecycle: Call only waits for attachment, while terminal delivery remains in Reset. Cancellation and the 30s bound continue through the existing paths, and the regression tests cover both the direct empty-input case and the retry-before-registration interleaving.

Local validation:

  • full pkg/sql/colexec/dispatch test suite
  • the end-to-end compile regression test, 10 consecutive runs
  • race runs for all three added regression tests
  • git diff --check

@XuPeng-SH
XuPeng-SH merged commit 69be5fb into matrixorigin:main Jul 13, 2026
40 of 43 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/remote-dispatch-empty-input-registration branch July 13, 2026 17:48
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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#25687

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

A remote dispatch currently waits for receiver attachment only when a
data batch reaches its send function. If the child produces no batches,
Dispatch.Call returns ExecStop immediately. An early
RemoteDispatchNotRegistered response can then outlive the producer:
cleanup removes the newly published UUID before the client's 200 ms
retry, and all later retries fail until the 30-second timeout.

This PR restores the remote-dispatch lifecycle invariant at the producer
boundary: successful terminal completion waits for all remote receivers
even when the input is empty. It reuses the existing receiver barrier,
context cancellation, and 30-second upper bound.

The production change is intentionally limited to the zero-batch remote
path:

- non-empty dispatch is unchanged;
- local-only dispatch is unchanged;
- an already attached empty dispatch adds only two boolean checks;
- a racing registration waits for the existing notify retry instead of
failing after 30 seconds;
- cancellation and unreachable receivers return through the existing
bounded error paths;
- no protocol, lock, goroutine, retry interval, or retained state is
added.

The regression tests cover direct empty-input attachment,
cancellation-cause propagation, and the exact end-to-end interleaving
where the first notify misses registration, the producer registers and
becomes empty, and the retry must attach before terminal cleanup. The
direct test was also run with the production fix removed and failed
immediately, proving that it detects the original bug.

## Testing

- make -j12
- make dev-build
- go test ./pkg/sql/colexec/dispatch
- go test ./pkg/sql/compile
- go test -race for the empty-dispatch tests
- go test -race for
TestRemoteNotifyRetryAttachesToEmptyDispatchBeforeCompletion
- go vet ./pkg/sql/colexec/dispatch ./pkg/sql/compile
- go vet with molint for both affected packages
- golangci-lint run -c .golangci.yml ./pkg/sql/colexec/dispatch
./pkg/sql/compile
- Multi-CN Docker reproduction with 5M, 4M, and 1M-row tables: expected
result 499999
  - concurrency 8: 200/200 passed; unfixed code failed 4/200
  - concurrency 16: 100/100 passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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#25687

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

A remote dispatch currently waits for receiver attachment only when a
data batch reaches its send function. If the child produces no batches,
Dispatch.Call returns ExecStop immediately. An early
RemoteDispatchNotRegistered response can then outlive the producer:
cleanup removes the newly published UUID before the client's 200 ms
retry, and all later retries fail until the 30-second timeout.

This PR restores the remote-dispatch lifecycle invariant at the producer
boundary: successful terminal completion waits for all remote receivers
even when the input is empty. It reuses the existing receiver barrier,
context cancellation, and 30-second upper bound.

The production change is intentionally limited to the zero-batch remote
path:

- non-empty dispatch is unchanged;
- local-only dispatch is unchanged;
- an already attached empty dispatch adds only two boolean checks;
- a racing registration waits for the existing notify retry instead of
failing after 30 seconds;
- cancellation and unreachable receivers return through the existing
bounded error paths;
- no protocol, lock, goroutine, retry interval, or retained state is
added.

The regression tests cover direct empty-input attachment,
cancellation-cause propagation, and the exact end-to-end interleaving
where the first notify misses registration, the producer registers and
becomes empty, and the retry must attach before terminal cleanup. The
direct test was also run with the production fix removed and failed
immediately, proving that it detects the original bug.

## Testing

- make -j12
- make dev-build
- go test ./pkg/sql/colexec/dispatch
- go test ./pkg/sql/compile
- go test -race for the empty-dispatch tests
- go test -race for
TestRemoteNotifyRetryAttachesToEmptyDispatchBeforeCompletion
- go vet ./pkg/sql/colexec/dispatch ./pkg/sql/compile
- go vet with molint for both affected packages
- golangci-lint run -c .golangci.yml ./pkg/sql/colexec/dispatch
./pkg/sql/compile
- Multi-CN Docker reproduction with 5M, 4M, and 1M-row tables: expected
result 499999
  - concurrency 8: 200/200 passed; unfixed code failed 4/200
  - concurrency 16: 100/100 passed
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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#25687

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

A remote dispatch currently waits for receiver attachment only when a
data batch reaches its send function. If the child produces no batches,
Dispatch.Call returns ExecStop immediately. An early
RemoteDispatchNotRegistered response can then outlive the producer:
cleanup removes the newly published UUID before the client's 200 ms
retry, and all later retries fail until the 30-second timeout.

This PR restores the remote-dispatch lifecycle invariant at the producer
boundary: successful terminal completion waits for all remote receivers
even when the input is empty. It reuses the existing receiver barrier,
context cancellation, and 30-second upper bound.

The production change is intentionally limited to the zero-batch remote
path:

- non-empty dispatch is unchanged;
- local-only dispatch is unchanged;
- an already attached empty dispatch adds only two boolean checks;
- a racing registration waits for the existing notify retry instead of
failing after 30 seconds;
- cancellation and unreachable receivers return through the existing
bounded error paths;
- no protocol, lock, goroutine, retry interval, or retained state is
added.

The regression tests cover direct empty-input attachment,
cancellation-cause propagation, and the exact end-to-end interleaving
where the first notify misses registration, the producer registers and
becomes empty, and the retry must attach before terminal cleanup. The
direct test was also run with the production fix removed and failed
immediately, proving that it detects the original bug.

## Testing

- make -j12
- make dev-build
- go test ./pkg/sql/colexec/dispatch
- go test ./pkg/sql/compile
- go test -race for the empty-dispatch tests
- go test -race for
TestRemoteNotifyRetryAttachesToEmptyDispatchBeforeCompletion
- go vet ./pkg/sql/colexec/dispatch ./pkg/sql/compile
- go vet with molint for both affected packages
- golangci-lint run -c .golangci.yml ./pkg/sql/colexec/dispatch
./pkg/sql/compile
- Multi-CN Docker reproduction with 5M, 4M, and 1M-row tables: expected
result 499999
  - concurrency 8: 200/200 passed; unfixed code failed 4/200
  - concurrency 16: 100/100 passed

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]: Empty remote dispatch can lose receiver registration and time out

3 participants