Skip to content

[Bug] TPCH Q16 hangs indefinitely: Shuffle execution engine deadlock in waitBatchOrEnd (TPCH 100G stuck for 15+ hours) #25922

Closed

Description

@Ariznawlll

Issue

TPCH Q16 (supplier count query) hangs indefinitely on TPCH 100G dataset due to a deadlock in the Shuffle execution engine. The query has been running for 15+ hours (normally completes in ~3 seconds). The root cause is that Shuffle consumer goroutines are permanently blocked in ShufflePool.waitBatchOrEnd() because the producer pipeline exited without sending the end-of-data signal.

This causes the entire TPCH 100G benchmark to stall — Q1-Q15 complete normally, but Q16 never returns.

Environment

Field Value
CI Run https://github.com/matrixorigin/mo-auto-test/actions/runs/29764528161/job/88440134273
Branch main
MO commit 0102f7b85bcb8d960d7cc16a14b71682a58e7910
Runner mo-srv-129 (10.222.1.129, IDC self-hosted)
Topology Single CN + Single TN (launch mode)
GOMEMLIMIT 80000 MiB
Stuck step Start TPCH 100G Test (started 2026-07-20 19:08:32 UTC, still running after 15+ hours)

Stuck Query (TPCH Q16)

SELECT p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt
FROM partsupp, part
WHERE p_partkey = ps_partkey
    AND p_brand <> 'Brand#35'
    AND p_type not like 'ECONOMY BURNISHED%'
    AND p_size in (14, 7, 21, 24, 35, 33, 2, 20)
    AND ps_suppkey not in (
        SELECT s_suppkey FROM supplier WHERE s_comment like '%Customer%Complaints%'
    )
GROUP BY p_brand, p_type, p_size
ORDER BY supplier_cnt desc, p_brand, p_type, p_size
  • Query started: 2026-07-20 19:10:19 CST (confirmed via mo_catalog.mo_sessions)
  • Running for: 912+ minutes (15.2+ hours) and still not completed
  • Normal duration: 3.0-3.2 seconds per turn (baseline from 2026-07-18 run)
  • Regression factor: ~10000x

Query Execution Plan

AP QUERY PLAN ON MULTICN(64 core)
Project
  -> Sort (supplier_cnt DESC, p_brand, p_type, p_size)
       -> Aggregate (count(distinct ps_suppkey))
            -> Aggregate (Group: p_brand, p_type, p_size, ps_suppkey)
                 shuffle: range(partsupp.ps_suppkey)
                 -> ANTI JOIN (hashOnPK: partsupp.ps_suppkey = supplier.s_suppkey)
                      -> INNER JOIN (hashOnPK: partsupp.ps_partkey = part.p_partkey)
                           shuffle: range(partsupp.ps_partkey)
                           -> Table Scan on partsupp
                           -> Table Scan on part (filter: p_size, p_brand, p_type)
                      -> Table Scan on supplier (filter: s_comment like)

Root Cause: Shuffle Deadlock

Goroutine Analysis (live pprof from debug HTTP :6060)

Total goroutines: 2404

Goroutine State Blocked Duration Location
85679 chan receive 435 min Scope.MergeRun (scope.go:375) — parent scope waiting for child pipelines
135584 select 433 min shuffle.(*Shuffle).Call → group.(*Group).Call → connector.(*Connector).Call
132044 select 433 min shuffle.(*Shuffle).Call → group.(*Group).Call → connector.(*Connector).Call
132039 select 433 min ShufflePool.waitBatchOrEnd (shufflepool.go:396)
135597 select 433 min ShufflePool.waitBatchOrEnd (shufflepool.go:396)
135578 select 433 min ShufflePool.waitBatchOrEnd (shufflepool.go:396)
135581 select 433 min ShufflePool.waitBatchOrEnd (shufflepool.go:396)
135582 select 433 min ShufflePool.waitBatchOrEnd (shufflepool.go:396)

Deadlock Chain

Producer pipeline (TableScan → Join → Filter)
  → Completes execution and goroutine exits
  → FAILS to send "end of data" signal to ShufflePool
  → Shuffle consumer goroutines stuck in waitBatchOrEnd() forever
  → Parent Scope.MergeRun() blocked on chan receive waiting for children
  → Query never returns

Key Evidence

  1. No producer goroutines remain: TableScan, HashBuild, and Filter goroutines for this query are gone — they exited without signaling completion.

  2. CPU is idle: 5-second CPU profile shows only 34.2% utilization, all in runtime internals (futex, syscall, selectgo). No query computation is happening.

  3. MySQL is responsive: The MO instance accepts new connections and runs other queries normally — only this specific Q16 session is deadlocked.

  4. mo_catalog.mo_sessions confirms: Session 019f80ef-ae51-7731-ba1a-7c49a40fdcfa has been running Q16 on tpch_100g database since 19:10:19 CST.

Baseline Comparison (2026-07-18, same runner, same config)

Metric Normal (7/18) Current (deadlocked)
Q16 per-turn cost 3.0-3.2 seconds >15 hours, not completed
Full 22-query turn ~110 seconds ❌ Stuck at Q16 in turn 1
5-turn total ~9.5 minutes ❌
CPU during query Normal ~0% (all blocked in wait)
Slowest queries (normal) Q15 ~15s, Q9 ~10s, Q17 ~9s Q16 > 15 hours

Suggested Investigation Areas

  1. pkg/sql/colexec/shuffle/shufflepool.go:396 — waitBatchOrEnd(): Add a timeout or context cancellation mechanism so consumers don't block forever if the producer dies.

  2. Producer pipeline exit path: Ensure all producer pipelines (especially TableScan → Join → Filter chains) send the end-of-data signal to the ShufflePool in all exit paths, including error/early-exit paths.

  3. pkg/sql/colexec/shuffle/shuffle.go:136 and shuffle.go:160: Review the shuffle Call logic for race conditions between producer completion and consumer waiting.

  4. Query timeout: Add a configurable query-level timeout so that deadlocked queries are eventually killed rather than running indefinitely.

How to Reproduce

  1. Build MO from commit 0102f7b8 with launch mode (single CN + single TN)
  2. Load TPCH 100G data
  3. Run ./run.sh -q all -s 100 -t 5 (TPCH 100G, 5 turns)
  4. Observe Q16 hanging indefinitely

Note: This may be non-deterministic — the deadlock depends on the timing of producer pipeline completion vs consumer goroutine scheduling.

Activity

  1. added
    kind/bug
    on Jul 21, 2026
  2. added theissue type on Jul 21, 2026
  3. added this to the MO-202607 milestone on Jul 21, 2026
  4. assigned and unassigned on Jul 22, 2026
  5. aunjgr commented on Jul 22, 2026

    @aunjgr
    Contributor

    fixed

  6. Ariznawlll commented on Jul 22, 2026

    @Ariznawlll
    CollaboratorAuthor
  7. Ariznawlll commented on Jul 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    新证据:TPCH 孤儿查询在 server 端运行 10+ 小时

    在 mo-auto-test bisect run 29914894557 中,通过直连 mo-srv-129 的 MO 实例发现:

    孤儿查询现场

    session_id:  019f8990-7770-7a08-b0fe-e8e4126bd267
    db:          tpch_100g
    query:       TPCH Q9 (profit, p_name like '%pink%')
    query_start: 2026-07-22 11:22:54 CST
    running:     36898 秒 (~10.2 小时)
    来源:        nightly run 29853201365 (已 cancelled)
    

    上一个 nightly run 的 TPCH job 被 cancel 后,server 端 Q9 查询没有被 kill,在 MO 上持续运行了 10+ 小时。后续新的 bisect run 启动后,TPCH 100G 测试步骤卡住 2+ 小时。

    MO server 状态

    • 2526 goroutines, 99.8% 在 runtime.gopark(空闲等待)
    • CPU 空闲,孤儿查询没有消耗计算资源
    • 但 session 和锁资源被占用,影响后续查询

    与本 issue 的关系

    本 issue 描述的 TPCH Q16 hang 和这个孤儿查询问题有相同的底层缺陷:客户端断开/超时后,server 端查询不自动终止。

    • Q16 hang 场景:客户端 1800s 超时后查询仍卡在 server 端的 shuffle/dispatch
    • 孤儿查询场景:job cancel 或客户端断开后查询永远不停

    两者都需要 server 端具备查询生命周期管理——当客户端不再存在时,自动终止对应的 server-side 查询。

  8. added 2 commits that reference this issue on Jul 23, 2026
    0d7eeb3
    27cf9a7
  9. assigned and unassigned on Jul 24, 2026
  10. aunjgr commented on Jul 24, 2026

    @aunjgr
    Contributor

    @Ariznawlll 还hung吗?麻烦验证一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s-1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions