Skip to content

[Bug]: Group continues spill reload after cancellation arrives at input EOF #26444

Closed

Description

@Ariznawlll

[Bug]: Group continues spill reload after cancellation arrives at input EOF

Summary

Group.Call checks cancellation only when the operator call begins. If the
input child reports EOF and the process context becomes canceled immediately
after that child call, Group continues to flush and reload its spill buckets,
then returns a normal result instead of context.Canceled.

This is particularly expensive for a large aggregation because the canceled
statement can still perform the complete spill readback and hash merge.

Reproduction

The focused white-box reproducer is:

pkg/sql/colexec/group/group_test.go
TestGroupSpillReloadHonorsCancellationAfterInput

It creates 65,536 distinct int32 keys, sets Group.SpillMem = 4096 to force
the group-count spill mode, and uses a child that cancels the process exactly
when it returns EOF. The first spill wave has already created 32 bucket files
before EOF. The expected result of the Group call is context.Canceled.

Run:

go test ./pkg/sql/colexec/group \
  -run TestGroupSpillReloadHonorsCancellationAfterInput -count=1 -v

Actual result

The test fails because Group.Call returns nil error after cancellation:

Expected error with "context canceled" in chain but got nil.

The operator diagnostics confirm that it proceeded into the spill reload path
after cancellation, including GroupSpillReloadBuckets=1,
GroupSpillReloadRecords=8, and GroupSpillReloadRows=2026.

Expected result

Once the pipeline context is canceled, Group should stop before doing more
spill I/O or spill-bucket hash merges, return the cancellation error, and let
the normal reset/free path release the bucket resources.

Reproducibility

Reproduced twice independently on origin/main at ebdc3de0f:

  1. First focused run: Group.Call returned nil after the spill was created.
  2. Second focused run: the same result; the recorded command exited with code
    1 only because the test correctly expected context.Canceled.

Suspected area

pkg/sql/colexec/group/exec2.go checks vm.CancelCheck(proc) only at the
start of Group.Call. The loops in pkg/sql/colexec/group/helper.go,
especially loadSpilledData, continue reading and merging spill records
without another cancellation check.

Scope

This report is limited to the Group spill reload cancellation path. It does
not change production code.

Activity

  1. added this to the MO-202607 milestone on Jul 30, 2026
  2. added
    kind/bug
    on Jul 30, 2026
  3. added theissue type on Jul 30, 2026
  4. self-assigned this
    on Jul 30, 2026
  5. XuPeng-SH commented on Aug 1, 2026

    @XuPeng-SH
    Contributor

    Roadmap grouping: #26563. Fix together with #26446/#26447 under one narrow invariant: after child EOF, observe cancellation before spill reload/final merge/materialization; during long work, check at bucket/run/chunk boundaries rather than per row. Reuse a shared test fixture, but do not change global ChildrenCall semantics or introduce a general cancellation/I/O framework.

  6. added a commit that references this issue on Aug 4, 2026
    7ca0dd2
  7. Ariznawlll commented on Aug 5, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:ace13bf4b43773dd962f03325b22f58ed31fee91
    • 部署方式:macOS/arm64 本地 Go 单测;受控 spill 文件服务与可取消 process.Context。
    • 测试日期:2026-08-05

    原问题验证

    执行 go test -count=3 ./pkg/sql/colexec/group,以及 go test -race ./pkg/sql/colexec/group。目标回归 TestGroupSpillReloadHonorsCancellationAfterInput 在 child EOF 后取消 context,断言 reload 不再继续并返回取消结果。

    Happy Path 覆盖

    1. TestGroupSpillReloadKeepsPreallocationBounded:spill reload 正常完成,预分配受字节上限约束。
    2. TestGroupByWithSum 与 TestGroupNoGroupBy:普通聚合/无 group key 的结果仍正确。
    3. TestGroupResetAndReuse:正常执行后 reset 可复用。

    Unhappy Path 覆盖

    1. EOF 后取消:TestGroupSpillReloadHonorsCancellationAfterInput,不会进入后续 reload/publish。
    2. spill 写入中取消:TestGroupSpillWriteHonorsCancellationAfterInputBatch、TestGroupSpillWriteStopsAtBucketBoundary、TestGroupSpillWriteStopsAfterLastBucket。
    3. 取消后清理并复用:TestGroupSpillReloadCancellationCleansAndReuses;断言临时资源被清理、下一次执行可用。

    白盒验证

    针对 group_test.go 执行 3 轮普通 UT 和 1 轮 -race,未发现 data race 或泄漏式重放。

    回归测试

    该问题依赖内部 spill reload 与取消时序,现由上述 Go UT 保留;普通 motr SQL 无法可靠将取消精确注入到 EOF 后 reload 边界,因此未重复加入 motr。

    测试证据

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

    测试结论

    测试通过。

  8. added 3 commits that reference this issue on Sep 17, 2026
    35939a4
    abe980a
    d0bf810
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