Skip to content

fix(frontend): reduce disconnect scan stalls during KILL - #32378

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/32362-main-owner
Nov 9, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/32362-main-owner

Conversation

@XuPeng-SH

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:

Part of #32362; keep the issue open. The 4.2-dev change is #32364; main already has a one-second disconnect probe without the 30-second grace described in that issue.

What this PR does / why we need it:

On main, an idle connection's KILL CONNECTION can hold the routine request mutex while closing its protocol. A disconnect scan that has already snapshotted that routine can then wait behind a slow close before it reaches another disconnected request. This change removes that lock-held close when the routine and its lifecycle controller are uncontended and idle. It seals the existing lifecycle controller before releasing the locks, so a reset or migration cannot acquire the session while the protocol is closing. Busy or contended paths retain their previous behavior; this does not guarantee that every disconnect scan is nonblocking.

A request finishing concurrently with KILL now hands connection closure to the existing connection owner after attempting its response. This closes an existing window where KILL and request completion could each leave closure to the other. No additional monitor, per-connection cache, or persistent close state is introduced.

The existing main-branch FIN/RST sampling policy is unchanged. In particular, main currently cancels a request after a client write-half-close; this PR does not change that limitation. During an account KILL of an idle connection, a concurrent subsequent KILL QUERY can now fail immediately because the connection is already sealed; the base implementation could instead wait for the close and report a no-op success. KILL QUERY against a still-running request remains supported.

Validation

  • Full ./pkg/frontend normal and race tests; ./pkg/proxy normal tests. Seventeen individually measured KILL, disconnect, reset, response and cleanup cases each passed 100 repetitions with -race.
  • Disposable authenticated single-CN SQL tests exercised RST and FIN after an uncommitted update, verified rollback and lock release, checked remote/self KILL, and recorded main's existing write-half-close behavior.
  • go vet, the repository-pinned molint, and incremental golangci-lint passed for the affected frontend/proxy/issues closure and final test delta. Native Darwin execution was not available.
  • In a local alternating base/candidate healthy-SQL comparison (8 active and 64 idle connections, 240,000 SELECT 1 calls per sample), base was 17.0k–18.7k QPS and this change 18.0k QPS; p95 was 0.819–0.899 ms and 0.828–0.854 ms respectively. Base itself varied ~10%, so these samples show no obvious large regression in this workload; they do not establish a general speedup or a production latency bound.

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

@XuPeng-SH

XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 9c227818db233108062d070ab83492c5aedde0dd

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: 9c227818db233108062d070ab83492c5aedde0dd

Assessment: approve

The fix reuses existing lifecycle admission and connection cleanup. Idle-close and request/KILL handoff paths are sound, with no actionable findings.

Model: gpt-6.1-sol / max

Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0

Validation:

  • Seventeen focused cases passed once under race, then each passed 100 repetitions with one exact test per command.

  • Preflight, native build, frozen-source/delta and formatting checks passed. All 23 receipts reconcile with retained logs in validation-index.json.

  • Reused author-reported full frontend normal/race, proxy normal, authenticated SQL rollback/KILL and static checks. Both discussion entries were assessed.

Limitations:

  • Substantive CI was pending in the frozen snapshot. Full-package/SQL/static evidence lacks raw attachments; Darwin execution was unavailable.

  • Busy or contended close paths and main’s existing write-half-close cancellation policy remain unchanged.

This branch was successfully deployed

No deployments
ci — efae6b7b Deployed Nov 9, 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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants