Skip to content

[Bug]: dedupjoin finalize swallows context cancellation when a worker result is missing #26375

Closed

Description

@Ariznawlll

Description

The dedupjoin finalize merger silently converts context cancellation into a successful end-of-stream when one parallel worker result is missing.

When receiveWorkerMsg returns nil because proc.Ctx is canceled, container.finalize returns nil. DedupJoin.Call then advances to End and returns ExecStop with no error.

This can make a canceled/failed parallel pipeline look successful. Because finalize is responsible for emitting unmatched build rows, the same path can also silently omit output.

Environment

  • MatrixOne main: f6dab28046d70412cec132f0068840896852101c
  • macOS arm64
  • Go 1.26.x

Reproduction

Add the following diagnostic test to pkg/sql/colexec/dedupjoin/join_test.go:

func TestDedupFinalizeMissingWorkerHonorsCancellation(t *testing.T) {
    proc := testutil.NewProcessWithMPool(t, "", mpool.MustNewZero())
    arg := &DedupJoin{
        NumCPU:            2,
        IsMerger:          true,
        Channel:           make(chan *WorkerJoinMsg),
        OnDuplicateAction: plan.Node_FAIL,
    }
    arg.ctr.state = Finalize
    arg.ctr.matched = &bitmap.Bitmap{}
    arg.ctr.matched.InitWithSize(1)

    ctx, cancel := context.WithCancel(proc.Ctx)
    proc.Ctx = ctx
    cancel()

    defer func() {
        arg.Free(proc, true, context.Canceled)
        proc.Free()
    }()

    res, err := arg.Call(proc)
    if !errors.Is(err, context.Canceled) {
        t.Fatalf("cancellation was swallowed: status=%v err=%v", res.Status, err)
    }
}

Run:

go test ./pkg/sql/colexec/dedupjoin \
  -run '^TestDedupFinalizeMissingWorkerHonorsCancellation$' \
  -count=1 -v

The failure reproduced twice with -count=1.

Actual Result

missing worker cancellation was swallowed: status=0 err=<nil>

Call returns ExecStop and no error.

Expected Result

Call should return context.Canceled (or the original terminal worker/pipeline error). It must not report successful end-of-stream when finalize could not collect all worker results.

White-box Analysis

pkg/sql/colexec/dedupjoin/join.go:

for cnt := 1; cnt < int(ap.NumCPU); cnt++ {
    msg := receiveWorkerMsg(proc.Ctx, ap.Channel)
    if msg == nil {
        return nil
    }
    // merge worker state
}

receiveWorkerMsg returns nil for both a closed channel and context cancellation. The caller does not inspect context.Cause(proc.Ctx) and therefore treats cancellation as successful finalize completion.

After finalize returns nil, Call sees no buffered output, transitions to End, and returns ExecStop with no error.

Impact

  • A canceled or failed parallel dedup pipeline can be reported as successful.
  • Unmatched build rows that should be emitted during finalize can be silently omitted.
  • The original terminal cause is lost, preventing correct retry and incident classification.
  • A missing worker and a genuinely empty/closed worker channel are indistinguishable at the caller.

Additional Information

This issue was found during colexec unhappy-path testing. It does not involve security-sensitive behavior.

Activity

  1. added this to the MO-202607 milestone on Jul 29, 2026
  2. added
    kind/bug
    on Jul 29, 2026
  3. added theissue type on Jul 29, 2026
  4. self-assigned this
    on Jul 29, 2026
  5. added a commit that references this issue on Jul 29, 2026
    de42504
  6. Ariznawlll commented on Aug 5, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:ace13bf4b43773dd962f03325b22f58ed31fee91
    • 部署方式:macOS/arm64 本地 Go 单测;DedupJoin worker mailbox 与可取消 context。
    • 测试日期:2026-08-05

    原问题验证

    执行 go test -count=3 ./pkg/sql/colexec/dedupjoin 与 go test -race ./pkg/sql/colexec/dedupjoin。TestDedupFinalizeMissingWorkerHonorsCancellation 构造缺失 worker result,验证 finalize 返回请求取消而不吞掉 context cancellation。

    Happy Path 覆盖

    1. TestDedupJoin、TestDedupJoinCapture、TestDedupJoinCapturePartialMatch:普通与 capture join 结果正确。
    2. TestDedupShuffleWorkersFinalizeTheirOwnPartitions、TestDedupFinalizeParallelMergePreservesDataAcrossReset:正常多 worker/bucket finalize 保持数据。

    Unhappy Path 覆盖

    1. 缺失 worker:取消必须胜出并返回。
    2. 并发取消:TestDedupFinalizeConcurrentCancellationReturns。
    3. worker failure / normal abort:TestDedupFinalizeWorkerFailureCleansTransferredMessages、TestDedupFinalizeWorkerFailureDoesNotWaitForMissingWorker、TestDedupFinalizeNormalAbortDoesNotHideCancellation。
    4. mailbox close、nil status、缺 mailbox:TestReceiveWorkerMsg_ContextCancel、TestReceiveWorkerMsg_ChannelClose、TestReceiveWorkerMsg_RejectsMissingMailboxAndNilStatus。

    白盒验证

    针对 join_test.go 完成 3 轮 UT 与 -race,覆盖 mailbox ownership、取消和 transferred-message cleanup。

    回归测试

    缺 worker result 的注入只能稳定在 operator/mailbox 级完成,保留为 Go UT;不新增 motr。

    测试证据

    执行命令:go test -count=3 ./pkg/sql/colexec/dedupjoin、go test -race ./pkg/sql/colexec/dedupjoin,均以 exit code 0 完成。

    测试结论

    测试通过。

  7. added 3 commits that reference this issue on Sep 17, 2026
    21d2d32
    b4d140b
    9076720
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions