Skip to content

fix(frontend): force recompile on each prepared execute to prevent hang - #25562

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-25526-main
Jul 10, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-25526-main

Conversation

@ck89119

@ck89119 ck89119 commented Jul 9, 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:

issue #25526

What this PR does / why we need it:

Fix prepared UPDATE...JOIN hanging on second execution through binary protocol
(COM_STMT_EXECUTE). First execution succeeds, second hangs forever.

Root Cause: The initExecuteStmtParam function caches and reuses a compiled
scope tree (prepareStmt.compile) across executions when no schema change is
detected. After the first execution, operators in the cached compile retain stale
state (e.g. hashbuild ctr, dispatch channels) from the isPrepare=true cleanup
path that skips Free(). On re-execution, hashbuild operators enter Call but
stall in build() → never reach handleRuntimeFilter → never send runtime
filter messages → scan receivers block forever in waitForRuntimeFilters
(confirmed via goroutine dump).

Fix: Restructure initExecuteStmtParam to always release the cached compile
(via FreeOperator + SetIsPrepare(false) + Release) and create a fresh one
with isPrepare=true on every execution. This follows the same pattern the
change=true path already used. The plan remains cached and reused; only the
compile (lightweight scope tree) is rebuilt. This avoids:

  • Resource leaks (proper release before replacement)
  • Execution path drift (isPrepare=true preserved for GetExecType)
  • Side effects in read paths (consistent recreation for all callers)

Verification: Reproduced with Go driver (interpolateParams=false) on
single-node mo-service. Goroutine dump confirmed scan receivers blocked in
MessageReceiver.ReceiveMessage with hashbuild never sending runtime filters.
After fix: both executions complete normally.

🤖 Generated with Claude Code

Prepared UPDATE...JOIN hangs on second execution through binary protocol
(COM_STMT_EXECUTE) because the cached compile retained stale operator state
(e.g. hashbuild ctr, dispatch channels) across executions. Scan receivers
block forever in waitForRuntimeFilters waiting for runtime filter messages
that never arrive because hashbuild operators stall in build() on re-execution.

Fix: restructure initExecuteStmtParam to always release the cached compile
and create a fresh one with isPrepare=true. This avoids:
- Resource leaks (proper FreeOperator+Release before replacement)
- Execution path drift (isPrepare=true preserved for exec type decisions)
- State mutation in read paths (consistent recreation for all callers)

The compile is freshly built from the plan each execution; the plan is
still cached and reused when no schema change is detected.

Fixes: matrixorigin#25526
Co-Authored-By: Claude <[email protected]>
@ck89119
ck89119 requested a review from XuPeng-SH as a code owner July 9, 2026 10:54
@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 →

Only rebuild the prepared-statement compile when a cached compile exists.
A nil cache means the statement was rejected for prepare-time compile
(e.g. AP query); unconditionally retrying failed with
ErrCantCompileForPrepare on every execution, adding a wasted compile
attempt per EXECUTE. TP statements keep the force-recreate semantics
that fix the stale-operator-state hang.

Also fixes the SCA gofmt failure (stray tab on an empty line) and adds:
- UTs for the rebuild logic (skip-without-cache, recreate-with-cache,
  surface recompile error), modified-block coverage 80%
- BVT for repeated execution of a prepared UPDATE...JOIN

Verified the original repro (binary protocol COM_STMT_EXECUTE twice)
completes without hang.

Fixes: matrixorigin#25526
Co-Authored-By: Claude Fable 5 <[email protected]>
@mergify mergify Bot added the queued label Jul 10, 2026
@mergify

mergify Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-10 08:07 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-07-10 10:06 UTC · at b29df0470f3aa28de9fca2b2f387881709e448bd · squash

This pull request spent 1 hour 59 minutes 29 seconds in the queue, including 1 hour 21 minutes 44 seconds running CI.

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

@mergify
mergify Bot merged commit 5222247 into matrixorigin:main Jul 10, 2026
23 of 24 checks passed
@mergify mergify Bot removed the queued label Jul 10, 2026

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.

4 participants