Skip to content

fix(moerr): keep cancellation identity through ConvertGoError and RPC - #29316

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
fengttt:fix-convert-go-error-cancel
Sep 24, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
fengttt:fix-convert-go-error-cancel

Conversation

@fengttt

@fengttt fengttt commented Sep 24, 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 #29315

What this PR does / why we need it:

load_data/load_data_parquet.sql fails intermittently in multi-CN CI at pq_file_fanout_rollback. It failed on #29303, whose change is unrelated.

[EXPECT RESULT]: invalid input: column name not found
[ACTUAL RESULT]: internal error: convert go error to mo error reading magic footer of parquet file: context canceled (read: 0)

Root cause

  • When one shard of a parallel load fails, it cancels its siblings.
  • The scope scheduler reports the failing shard's error by recognising each sibling's error as that cancellation (normalizeScopeRunError / preferPrimaryScopeResult, via errors.Is).
  • moerr.ConvertGoError formatted every Go error into an internal error. So a context cancellation or deadline, often wrapped by a library, stopped matching errors.Is(err, context.Canceled/DeadlineExceeded), and whichever shard's result was collected first won.

It's not only the parquet reader:

  • The planner's parquet footer read (compile.go) flattens the same way.
  • The four RPC error encoders (pkg/pb/{pipeline,shard,lock,query}) go through ConvertGoError too, so a remote scope's cancellation reached the coordinator as an internal error.
  • About 88 call sites check errors.Is against the context sentinels, including the frontend, CDC and RPC clients.

Fix, in moerr

  • Conversion: ConvertGoError converts a context error, wrapped or not, to one of two new codes. The message is the original text.
    • ErrContextCanceled (20109), sent to clients as MySQL ER_QUERY_INTERRUPTED.
    • ErrDeadlineExceeded (20110). A deadline joined with a cancellation keeps the deadline.
  • Error.Is: it matches only those two codes to context.Canceled / context.DeadlineExceeded. errors.Is then behaves after conversion as it did before, and also after an RPC round trip, because the code is what's serialized.
  • Unaffected errors: errors built directly, such as a killed query (ErrQueryInterrupted) or a statement timeout (ErrQueryTimeout), don't gain new errors.Is matches.
  • RPC contract: the result is still a *moerr.Error, as the RPC encoders require. Returning raw context errors panicked those paths.
  • Mixed versions: older nodes decode the new codes with their message and MySQL code intact, because unmarshalling doesn't validate codes.

This replaces the parquet-only convertReaderError from the first commit of this PR. The parquet reader uses moerr.ConvertGoError again.

Tests

Each of these fails without the change:

  • TestConvertGoErrorKeepsContextIdentity: the mapping, MySQL codes, kept message, marshal/unmarshal round trip, deadline-over-cancellation for joined errors, and that directly built ErrQueryInterrupted / ErrQueryTimeout / internal errors are unaffected.
  • TestPreferPrimaryScopeResult: a sibling's parquet cancellation, both converted locally and decoded from pipeline.EncodedMessageError, resolves to the failing shard's error.
  • TestParquetOpenFileCanceledBySibling: opening a real parquet file with a context canceled by a sibling reports ErrContextCanceled, which matches context.Canceled.

Other checks:

  • go test: common/moerr, sql/compile, sql/colexec/external, pb/..., cdc, txn/service, util/export/etl, sql/plan/function/ctl, frontend, lockservice, shardservice and queryservice all pass.
  • BVT: no expected result contains the old flattened cancellation text.
  • make static-check: 0 issues.

The CI race itself doesn't reproduce locally (60/60 single-node runs gave the expected error), so the tests cover the mechanism deterministically.

Not covered

Code that flattens errors itself, e.g. moerr.NewInternalErrorf("...%v", err) or err.Error(), still loses the identity. Those sites need routing through ConvertGoError wherever a cancellation can reach them; that's a separate follow-up.

🤖 Generated with Claude Code

…ellation

When one shard of a parallel parquet LOAD fails, it cancels its
siblings, and the scheduler reports the failing shard's error: a
sibling's error that is a cancellation from that pipeline is resolved
to the cancel cause (normalizeScopeRunError / preferPrimaryScopeResult).
That only works if the cancellation is recognisable with errors.Is.

The parquet reader passed every library error through
moerr.ConvertGoError, which formats it into an internal error. A
sibling canceled mid-read reported parquet-go's "reading magic footer
of parquet file: context canceled" as "internal error: convert go error
to mo error ...", no longer a cancellation, so whichever shard result
was collected first won. load_data_parquet's pq_file_fanout_rollback
case failed intermittently in multi-CN CI this way, reporting that
instead of "invalid input: column name not found".

The parquet reader now converts library errors with convertReaderError,
which returns a cancellation or deadline unchanged and otherwise defers
to moerr.ConvertGoError. ConvertGoError itself is unchanged: the RPC
error encoders rely on it always returning *moerr.Error.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@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 →

Replace the parquet-only convertReaderError with a central fix.

moerr.ConvertGoError formatted every Go error into an internal error, so
a context cancellation or deadline (often wrapped by a library, e.g.
parquet-go's "reading magic footer of parquet file: context canceled")
stopped matching errors.Is(err, context.Canceled/DeadlineExceeded). The
scope scheduler relies on that to report a failing shard's error
instead of a canceled sibling's (matrixorigin#29315), and the frontend, CDC and RPC
clients check it too. The four RPC error encoders also flatten through
ConvertGoError, so a remote cancellation arrived as an internal error.

ConvertGoError now converts a context error to one of two new codes,
ErrContextCanceled (MySQL ER_QUERY_INTERRUPTED) and ErrDeadlineExceeded,
keeping the original text as the message; a deadline joined with a
cancellation keeps the deadline. moerr.Error gains an Is method that
matches only those two codes to context.Canceled and
context.DeadlineExceeded, so errors.Is behaves after conversion, and
after an RPC round trip since the code is serialized, as it did before;
errors built directly (a killed query, a statement timeout) are
unaffected. The result is still a *moerr.Error, as the RPC encoders
require. Older nodes decode the new codes unchanged, as unmarshalling
does not validate codes.

Tests: conversion, MySQL code, message, marshal round trip and the
unaffected codes (moerr); a locally converted and an RPC-decoded reader
cancellation resolve to the failing shard's error
(TestPreferPrimaryScopeResult); a parquet open canceled by a sibling
reports a cancellation (external). All fail without the change.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@fengttt fengttt changed the title fix(external): report the failing shard, not a sibling's parquet cancellation fix(moerr): keep cancellation identity through ConvertGoError and RPC Sep 24, 2026
@fengttt

fengttt commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Related: #29290 (unpublished S3 cleanup ownership) depends on this PR on its failure path — see review #29290 (review).

That PR returns errors.Join(handlerErr, cleanupErr) from remote pipelines when S3 cleanup fails, which goes through EncodedMessageError → ConvertGoError. For a remote scope canceled because a sibling failed, this PR keeps Join(context.Canceled, cleanupErr) recognisable as a cancellation, so preferPrimaryScopeResult still reports the primary shard's error; without it the #29315 symptom comes back via that path. It's another instance of the "code that flattens errors itself" follow-up listed under Not covered above — non-cancellation errors joined there still lose their code, which is raised on #29290.

🤖 Generated with Claude Code

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

GPT-6 high review — APPROVE at exact head dfd5050.

Reviewed context-sentinel identity preservation through moerr/RPC conversion. No blocking findings.

@mergify mergify Bot added the queued label Sep 24, 2026
@mergify

mergify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-24 09:23 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-24 09:51 UTC · at e01bf10a75a5b2c15414c8be5dbc2544d28a1f73

This pull request spent 28 minutes 18 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated
> This pull request seems to come from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable ["Allow edits from maintainers"](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) on this pull request, or update the branch manually.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

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.

3 participants