Skip to content

[4.2-dev] fix(frontend): cancel active queries on TCP FIN - #32743

Merged
XuPeng-SH merged 2 commits into
4.2-devfrom
codex/32436-42-fin-cancel
Nov 14, 2026
Merged

XuPeng-SH merged 2 commits into
4.2-devfrom
codex/32436-42-fin-cancel

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement

Which issue(s) this PR fixes:

Related to #32436 and #32362. This PR covers Linux TCP; it does not claim to complete the cross-platform issue.

What this PR does / why we need it:

On 4.2-dev, an ordinary TCP FIN received during a request could leave the query and its transaction running until the request was at least 30 seconds old. This makes the existing Linux TCP probe recognize POLLRDHUP on the existing five-second liveness scan. It preserves the guarded reset probe and does not read queued input or consume socket errors. No per-connection worker or new timer is added.

The monitor rechecks request state before retiring a TCP connection and avoids blocking later scans on a busy legacy-connection lifecycle lock. Non-TCP connections retain their existing 30-second request-age policy; Darwin retains its existing behavior. A TCP write half-close is deliberately treated as a disconnect and can cancel an active request. Detection and cleanup remain subject to scheduling and downstream cancellation, and there is no hard five-second completion guarantee.

Validation

  • Authenticated MySQL/embedded-cluster regression: FIN and RST during active SQL roll back an explicit transaction and release a same-key waiter already observed in the lock queue; an independent session verifies the rolled-back value. A half-close cancels its request, while a connected client completes a six-second query and reuses the session.
  • The same FIN regression against the exact pre-fix production code fails at the 25-second request-age guard; with this change it passes before that guard.
  • Linux pkg/frontend package tests in normal and -race modes, plus 18 directly affected tests under -race (100 repetitions each); the public SQL regression also passed under -race.
  • gofmt, go vet, and the branch's selected molint / golangci-lint checks passed. molint reports the existing unchanged Routine.handleRequest recover warning; golangci-lint reports zero issues.
  • Synthetic comparison using 10,000 distinct loopback connections: 1% and 100% active scans remain in the same measured range with zero allocations; a separate mixed test canceled 100 FIN requests and kept 9,900 healthy requests. These are scan samples, not production throughput, CPU, or tail-latency guarantees.

Coordination with #32723

#32723 adds buffered TLS connection support and a test that expects a write-half-closed connection to remain active. On its then-current head, the changes applied together and focused buffered-TLS tests passed under -race after adapting that test to this PR's accepted half-close policy. When the branches meet, that test's expectation must be updated; this PR does not modify #32723's branch.

@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 →

@mergify

mergify Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: c4abd9196eaecdb1a711824daecb8d5844f9b08e

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: c4abd9196eaecdb1a711824daecb8d5844f9b08e

Assessment: approve

The FIN fix reuses the existing monitor and lifecycle ownership without adding workers or timers. Cancellation, cleanup and the explicit half-close policy are coherent and covered by tests. No actionable defects remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Frontend package passed normal and race runs: 1,655 test roots each, with one unrelated explicit skip.

  • All 18 focused tests passed normal/race runs and 100 race repetitions each: 1,800 repetitions total.

  • Authenticated SQL regression passed normal/race runs, covering FIN/RST rollback, lock release, half-close cancellation and healthy-session reuse.

  • Formatting, build and vet passed. Source, native provenance, discussion coverage, receipts and logs reconciled in validation-evidence.json.

Limitations:

  • Executed on Linux amd64 with Go 1.26.6; Darwin and integration with sibling PR #32723 were not exercised.

  • Author benchmark claims were not independently reproduced; relevant CI runs were pending in the supplied snapshot.

@XuPeng-SH

XuPeng-SH commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: f9de4bccf346851c4165eaccc52f2a0a3091c738

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: f9de4bccf346851c4165eaccc52f2a0a3091c738

Assessment: approve

FIN handling extends the existing monitor while preserving request admission, cancellation and cleanup ownership. Non-consuming probes, try-lock retries and bounded caches cover healthy and contended paths without new workers or timers. The intentional half-close policy and rollback/lock-release oracles are coherent. No actionable findings remain.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed all six changed files, affected owners/consumers, both linked issue discussions and all five PR discussion entries. discussion-assessment.json covers every key exactly once.

  • Receipt-backed local checks passed: private /tmp and loopback preflight; source, formatting and semantic-input audit; final discussion/receipt audit. Go reports 1.26.6 linux/amd64. Logs and exact commands are reconciled in validation-summary.json.

  • Reused execution evidence from evidence.json reviews:5900433326 at c4abd91: frontend normal/race runs with 1,655 roots each and one unrelated skip; 18 focused normal/race cases and 100 race repetitions each; authenticated SQL normal/race coverage of FIN/RST rollback, lock release, half-close cancellation and healthy-session reuse. All six changed files and relevant frontend, fixture, transaction, lock-service, embedded-cluster, module and native inputs match that revision; material rebase changes were inspected.

  • The frozen current-head shared build succeeded. UT, SCA, coverage, proxy/pessimistic BVT and Go analysis remain pending in the supplied snapshot and are not counted as passes.

Limitations:

  • No fresh native/runtime suite was executed. Prior runtime results are attributed to the supplied review; its raw per-case logs and exact commands are not included in this job.

  • Prior runtime coverage is Linux amd64 with Go 1.26.6. Darwin, sibling PR #32723 integration and an independent performance campaign were not exercised.

  • Retirement can wait for lifecycle contention and downstream cancellation/cleanup scheduling; the monitor interval is not a hard end-to-end completion deadline.

@XuPeng-SH
XuPeng-SH merged commit 7317bf9 into 4.2-dev Nov 14, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/32436-42-fin-cancel branch November 14, 2026 16:51
XuPeng-SH added a commit that referenced this pull request Nov 16, 2026
## What type of PR is this?

- [x] API-change
- [x] BUG
- [x] Improvement
- [x] Documentation
- [ ] Feature
- [x] Test and CI
- [x] Code Refactoring

## Which issue(s) this PR fixes:

Related to #29928 and #26068. Addresses the ENUM comma-member
representation/replay portion of consolidated #30771, including original
report #30776. Binary-collation identity and unrelated HEX behavior
remain tracked by that open issue.

Native 4.2 companion to SDK PR #32671. The SDK's supported paths on
published 4.2.8 do not depend on this native PR.

## What this PR does / why we need it:

Preserve the relevant protocol, schema replay, FULLTEXT, parser, Stage,
Parquet and branch fixes on 4.2-dev. Ordinary scalar display stays
exactly as in the base: INT(32), BOOL(0), BIGINT UNSIGNED(64), and the
existing FLOAT/date/text conventions. The restored scalar golden rows
remain unchanged.

### Complete ENUM member domains

The old comma join maps both ENUM('a,b','c') and ENUM('a','b','c') to
the same catalog text. The earlier PR mitigation rejected comma-bearing
declarations. This revision removes that restriction and preserves the
actual members and ordinals:

- Keep ordinary domains in the existing encoding. Use explicitly tagged,
counted byte framing for comma-bearing and singleton-empty domains. The
tag and payload form one authoritative pair; readers never guess from a
string prefix.
- Carry the pair through existing plan/native/catalog/TAE containers,
views/CTEs, schema copies, ALTER, imports, index/FK metadata and
tooling. Retain the 16/20-byte native layouts by using the reserved type
slot; add enum_encoding field 8 to plan.Type.
- Preserve existing two-argument conversion overloads as legacy
encoding. Append the tagged overloads, reuse one codec/lookup owner and
decode constant domains once per batch. Unknown/malformed domains remain
errors under IGNORE.
- Preserve stored ordinal zero separately from a declared empty member
through typed INSERT SELECT, checked remapping and frozen data-branch
output. The background AST entry reuses ordinary compilation,
transactions and constraints; normal strict INSERT of numeric zero still
fails.
- Stop hidden-ordinal propagation at comparison/counting set-operation
boundaries. UNION DISTINCT and MINUS counterexamples now match their
visible SELECT results; UNION ALL preserves storage ordinals and
multiplicity.
- Replay native COLUMN_TYPE and SHOW CREATE correctly under ordinary and
NO_BACKSLASH_ESCAPES modes, including prepared mode changes, quotes,
backslashes, NUL/CRLF and Unicode.

### Other retained fixes

- Drain frontend-owned TLS read-ahead bytes in both handshake branches
and retain TCP ownership for terminal detection. Reuse the existing
monitor and current 4.2 FIN/write-half-close cancellation policy from
#32743.
- Quote FULLTEXT identifier components through existing
planner/post-DML/ISCP owners and retain async parser parameters.
- Correct numeric token boundaries, including incomplete signed
exponents, while retaining 4.2 DOUBLE wire metadata.
- Preserve Stage host-form URIs and support encoded logical names in
path form, atomic combined ALTER, ENABLE=false and executing-session
SQL-mode status.
- Accept representable Parquet FLOAT32 infinities while preserving
finite-overflow, NaN and signed-zero behavior; retain the inlineable
normal conversion path. ENUM CSV/JSON/Hive/Parquet consumers share the
domain reader.
- Persist database branch identity in the existing dat_type field,
retain receipt/target checks, serialize deletion through existing DDL
locks/RC retry, and preflight source identity before restore effects.

## Compatibility and limits

- Existing flattened ENUM data retains its historical split
interpretation and ordinal mapping. Published fixtures show a/b/c at
ordinals 1/2/3; saved original CREATE SQL is insufficient to safely
regroup live values. No automatic repair or migration is performed.
- New tagged data requires capable binaries and schema consumers.
Stopped upgrades from 4.2.1 and 4.2.8 are qualified. Mixed-version
operation, old-binary reads of the new encoding and supported downgrade
are not.
- SET's comma prohibition stays unchanged. Existing binary-collation
identity, canonical BOOL reflection (#32746), lost historical view
provenance and unmarked empty-branch limitations are not closed.
- Existing branch-identity rollback and new path-form Stage URI limits
still apply. Published releases are unchanged; a release containing this
PR is required for its native capabilities.

## Validation

Runtime optimization qualified at a65a050, based on c5623e4 and
compared with 4.2-dev 25305b6. The subsequent CI-only read-buffer
cleanup is 3d34894. All fresh work ran
on 57/Linux/amd64, with source-matched CPU native libraries and
task-owned data/temp directories outside /tmp.

| Runtime follow-up check | Result |
| --- | --- |
| Types and function owners, -short -tags=matrixone_test, Go 1.26.4 and
1.27.1 | 176 + 1,297 root passes per toolchain; one existing
TestDecimal128Float skip per toolchain |
| Exact behavior tests | Leading/interior/trailing empty members,
arbitrary bytes, per-row changing domains/tags, identical text with
different tags, NULL and fatal oversized-domain errors under IGNORE pass
|
| Differential codec fuzz, Go 1.26.4 | 330,370 executions with a
30-second budget; no failure |
| Owning list/build/vet and molint, Go 1.26.4 | Exit zero; configured
incremental golangci reports zero issues |
| Maintained real-service BVT | 121/121 twice, checked-in expected
results unchanged; zero failed/ignored/abnormal statements; no genrs |
| Independent public SQL/client oracle | Nine groups / 185 SQL
operations pass: default/NBE/prepared replay, empty/zero ordinals, ALTER
atomicity/backfill/remap, view/CTE/CTAS, FK, INSERT SELECT, CSV/JSON and
scalar spelling |
| Service lifecycle | Both isolated instances shut down normally;
existing instance preserved |
| Independent design, implementation and final review | gpt-6.1-sol /
max; PASS; zero open blockers; reviewed delta d861af1862b9 |

Full prior implementation qualification is recorded at f9c839a: 7,159
roots across 15 owners, 2,143 frontend/external race roots and focused
100-repeat lifecycle stress, actual two-CN propagation, frozen branch
output/restore and stopped upgrades from published 4.2.1/4.2.8. The
runtime follow-up at a65a050 confirmed 138 of its 143 PR paths
byte-identical to that reviewed version. This follow-up changes one
common legacy traversal, two owner test files and two design/evidence
documents. Older broader evidence retains its stated source and scope;
it is not represented as a fresh release/SDK, cross-cluster CDC or
production-checkpoint qualification. Hosted CI must report on the pushed
head separately.

### CI-only read-buffer cleanup

The failed [UT Coverage
job](https://github.com/matrixorigin/matrixone/actions/runs/43801930042/job/133084100487)
reports a checked-allocator missing free of 27 bytes from
TestLazyCacheFSReadsMagicPrefixedRemoteObjectsWithoutLocalChecksum after
PASS. The final Coverage job is blocked by the absent UT profile; it did
not compute a coverage-rate verdict.

- The same exact test fails on clean base 25305b6 and original head
a65a050 under Go 1.26.4, -short -tags=matrixone_test, set-mode
package coverage, MO_MALLOC_DEBUG=1 and GOGC=1. The toolfs sources match
on both revisions.
- Existing test callers omit IOVector.Release; FileService.Close does
not own those read results. Register five vector releases before
assertions and copy the eviction helper's returned bytes before release.
- All 26 toolfs roots pass normal, checked-coverage and race modes; each
of the four affected tests passes 100 checked-coverage and 100 race
repetitions. Owner build/vet/molint exit zero; configured incremental
golangci reports zero issues.
- This follow-up changes test cleanup and its evidence document.
Production sources and coverage policy are unchanged, so the qualified
ENUM performance sources are preserved. Whole hosted CI remains a
separate result on 3d34894.
- Independent final review: gpt-6.1-sol / max, PASS; zero open blockers;
reviewed delta 34e8c37965ca.

## Performance versus current base

Same maintained benchmark source on base 25305b6, original PR
c5623e4 and candidate; CPU 23, GOMAXPROCS=1. The six dynamic
controls plus scalar display use seven interleaved rounds of 500 ms per
revision on each Go toolchain. Complete 54-case legacy and 54-case
tagged matrices use three interleaved 100-ms rounds each. These are
vector-function microbenchmarks, not end-to-end SQL throughput.

The old PR's dynamic regression reproduces on Linux; scalar display on
Go 1.27.1 is 127.7 -> 146.6 ns (+14.80%). The legacy reader now uses its
existing checked count to traverse exact comma-byte boundaries with
strings.IndexByte. The original strings.Split already counted
internally: this change reduces general split dispatch/check overhead
while retaining tag/size/member validation, independent ParseEnum
oracles and the same allocation bounds. No global/payload-equality cache
or row/data-shape special case is added.

| 3-member legacy domain | Go 1.26.4 candidate/base | Go 1.27.1
candidate/base |
| --- | ---: | ---: |
| Dynamic 64 rows: display / name / numeric | -0.15% / +1.20% / -0.07% |
+0.95% / +1.35% / +0.27% |
| Dynamic 1,024 rows: display / name / numeric | -0.15% / +0.90% /
-0.40% | -0.30% / +0.11% / -0.96% |
| Scalar constant display | +3.26% | +2.21% |

Bytes/allocations are unchanged for those controls. No legacy short-run
median in the complete matrices exceeds 10% versus base (maximum +7.70%
on Go 1.26.4 and +5.72% on Go 1.27.1). The sole tagged short-run point
above 10%, dynamic 64-member/1,024-row name lookup on Go 1.26.4, is
retained and remeasured over seven fixed longer rounds: original PR
655.833 us -> candidate 649.588 us (-0.95%), same 1,027 allocations.

Large constant-batch gains remain. Go 1.27.1 complete-matrix medians:

| Constant domain, 1,024 rows | Base | Candidate | Allocations |
| --- | ---: | ---: | ---: |
| 3 members, display | 49.517 us | 13.979 us | 1,026 -> 3 |
| 64 members, display | 648.679 us | 15.525 us | 1,026 -> 3 |
| 64 members, numeric validation | 641.309 us | 5.151 us | 1,026 -> 3 |
| 64 members, indexed name lookup | 18.257 us | 18.250 us | 76 -> 76 |

Residual small costs are reported, not described as universal speedups
or zero regression. The candidate has not been retimed on Darwin/arm64;
the earlier Darwin QA finding is not claimed resolved on that platform
from Linux evidence alone.

[Domain
design](https://github.com/XuPeng-SH/matrixone/blob/3d348941273493135f083c3c8a9eb581558f5e49/docs/design/enum_member_encoding_42.md)
· [Compatibility, evidence scope and detailed
performance](https://github.com/XuPeng-SH/matrixone/blob/3d348941273493135f083c3c8a9eb581558f5e49/docs/design/python_sdk_42_compat_validation.md)

---------

Signed-off-by: XuPeng-SH <[email protected]>
Co-authored-by: davis zhen <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch had an error being deployed

1 failed deployment
ci — f9de4bcc Deployed Nov 14, 2026 by XuPeng-SH
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 kind/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants