Skip to content

[Bug]: mo_ctl flush bad target leaks errno 0 ExpectedEOB #31663

Closed

Description

@Ariznawlll

Description

mo_ctl('dn', 'flush', <target>) handles invalid targets with three distinct broken error paths, each failing hygiene in a different way. The handler (pkg/sql/plan/function/ctl/cmd_flush.go) parses the target as TableId or DbName.TableName[.AccountId], but none of its failure modes produce a proper user-facing error:

target result problem
'' (empty) ERROR 20101 (HY000): internal error: handleFlush: table id parse fail internal-error code for what is invalid input; message leaks the internal func name
'a' / '!!!' (any single junk segment) same 20101 internal error should be 20301 invalid input with usage hint
'nonexistent_db.anything' (2 segments, db does not exist) ERROR (0, 'ExpectedEOB') — SQLSTATE-less, errno 0, message is a raw internal sentinel token StorageEngine.Database() returns the internal OkExpectedEOB code when the db is not visible; handleFlush propagates it to the client un-translated
'a.b.c' (3 segments, bad account) ERROR 20101: internal error: handleFlush: invalid account id same internal-code-for-input problem

The (0, 'ExpectedEOB') leak is the worst case: clients see errno 0 (which conventionally means success) plus a token from the internal error-code space, identical in shape to the previously fixed leaks in #30506 (temp-table DDL path) and #27463 — this is the same leak class resurfacing through the mo_ctl administrative path, which was not covered by those fixes.

For contrast, the sibling command mo_ctl('cn','reader', ...) was fixed in #31499 and now correctly answers ERROR 20301: invalid input: invalid reader ctl parameter "", expect cmd:cfg:tid1,tid2[:blk_cnt], e.g. ... — a clean invalid-input code with a usage hint. The flush path never received the same treatment.

Impact

  • Monitoring/alerting keyed on status='Failed' AND err_code=0 misses these failures entirely; SIEM rules see a bogus errno-0 error.
  • The raw sentinel exposes an internal mechanism name to SQL clients (information disclosure / confusing UX for DBAs running documented admin commands).
  • A DBA typo'ing the flush target gets an "internal error" instead of a usable message, since the valid usage (DbName.TableName[.AccountId] / numeric TableId) is only documented in source comments.

Expected behavior

  • Empty/mal-formed target → 20301 invalid input with a usage hint, mirroring the reader handler.
  • Nonexistent database → normal 1049 Unknown database/1146 style error, i.e. handleFlush must translate OkExpectedEOB from Database() the way DDL paths now do.

Reproduction (main @ c6683bd, 2026-10-29 build)

SELECT mo_ctl('dn', 'flush', '');                    -- 20101 internal error: handleFlush: table id parse fail
SELECT mo_ctl('dn', 'flush', '!!!');                -- 20101 same
SELECT mo_ctl('dn', 'flush', 'nonexistent_db.x');   -- ERROR (0, 'ExpectedEOB')
SELECT mo_ctl('dn', 'flush', 'a.b.c');              -- 20101 handleFlush: invalid account id
-- control: existing db, existing table works fine:
SELECT mo_ctl('dn', 'flush', 'mc.t');               -- OK JSON
-- control: existing db, missing table is properly reported:
SELECT mo_ctl('dn', 'flush', 'mc.nosuch');          -- 1146 no such table mc.nosuch

The 1146 path proves proper translation already exists downstream (Relation() errors arrive correctly); only Database()'s EOB return and the input-parse failures bypass it.

Activity

  1. added
    kind/bug
    on Oct 29, 2026
  2. added this to the MO-202610 milestone on Oct 29, 2026
  3. added theissue type on Oct 29, 2026
  4. added a commit that references this issue on Oct 29, 2026
    65a1a79
  5. XuPeng-SH commented on Oct 30, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged #31792 (65a1a79461de7207f2fd0af40c6d1a3e76eba68e): this isolated QA run inspected the merged source and issue history, but did not execute current-head functional tests or live SQL because available headroom under the existing resource guard was insufficient. Please verify malformed flush target errors, missing database 1049/42000, preservation of other errors and connection reuse. PR author-reported results are separate evidence and are not results of this QA run.

  6. slyunnn commented on Nov 2, 2026

    @slyunnn

    Regression and extended verification for #31663 (2026-11-02)

    Verification Environment

    • Main snapshot fetched before testing: d24f446e1e94a58c329d422519f7aad621cdcd05 — perf(sql): cost literal LIKE prefix ranges with analyzed distributions (#31940).
    • Clean native build; executable metadata and git_version() at all endpoints confirmed d24f446e1e.
    • Fresh local topology: 2 CN / 1 TN / 1 Log service / Proxy. Proxy localhost:6001, CN1 localhost:16001, CN2 localhost:16002 were reachable and each executed all live flush/error/recovery cases.
    • Python 3.14 with PyMySQL over MySQL text-query protocol. Error numbers and SQLSTATE were decoded from actual MySQL ERR packets. Existing BVT additionally ran through JDBC at the Proxy.

    What Was Covered

    • OK — Original empty/junk targets and invalid account/segment forms return 20301/HY000 with the accepted TableId or DbName.TableName[.AccountId] usage; no internal-function error is exposed.
    • OK — Missing database returns 1049/42000; an existing database's missing table retains 1146/42S02. No errno 0 or ExpectedEOB leaks.
    • OK — Valid qualified table, explicit current account, and numeric table-ID flush targets: 9 successful form/endpoint combinations.
    • OK — Empty name components, excessive segments, unsigned-ID overflow and long Unicode input. Error echoes are bounded without broken Unicode.
    • OK — 36 actual ERR-packet assertions, each followed on the same connection by SELECT 1, a valid flush and an exact full-row readback. All fixture databases removed.
    • OK — Owning-package tests cover preservation of unrelated database/relation errors, missing transaction operator, wrong service, real payload construction and no-shard behavior.
    • Not covered — Cross-tenant authorization and injected storage failures in the live cluster; unrelated-error preservation was checked in the owning unit tests instead.

    Findings

    Related fix: PR #31792, merge 65a1a79461de7207f2fd0af40c6d1a3e76eba68e — fix(ctl): classify invalid flush targets and missing databases. Included in the tested main snapshot. Invalid input is classified explicitly, the missing-database sentinel is translated, and unrelated error classes remain intact.

    MOTR / BVT Coverage

    • Full owning pkg/sql/plan/function/ctl package passed: 51 top-level tests plus 16 subtests, no failures or skips, including all 9 flush-focused top-level tests.
    • Existing test/distributed/cases/function/ctl_flush_error_classification.sql was replayed twice against its checked-in expected result: each run 15/15 statements passed, 0 failures/skips/abnormal results.
    • No test files changed, so no recording, duplicate MOTR case, commit or PR was needed. Flush recovery checks and BVT replay were sequential to avoid fixture-cleanup interference; no engine-parallelism claim is made.

    Final Conclusion

    Fixed on the tested main snapshot. Large-data regression is not required: the faulty boundary is target parsing and error translation, not table cardinality or flush throughput.

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions