Skip to content

fix: drain proxy connection work during shutdown - #33104

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/proxy-shutdown-handlers
Nov 23, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/proxy-shutdown-handlers

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Test and CI

Which issue(s) this PR fixes:

Refs #32745 (main flaky CI tracker)
Related: #32744 (4.2-dev flaky CI tracker)

The observed crash was on main in PR #33058. The 4.2-dev branch uses a different Goetty version and does not contain the same test; this PR does not claim that the identical failure has been reproduced there or close either tracker.

What this PR does / why we need it:

Proxy shutdown disconnected sessions without waiting for their handlers. A handler could then attempt disconnect cleanup after its query client and service runtime had been released, causing a nil-runtime panic.

Make the existing connection owner cancel and drain handlers, tunnel pipes and in-progress transfers before releasing shared dependencies. Keep event delivery cancellable before it is accepted, retain acknowledgements after acceptance, and start both forwarding directions before processing traffic so an immediate COM_QUIT cannot publish a still-used backend to the connection cache. Preserve disconnect cleanup for in-flight SQL and remove the redundant EOF cache fallback. Both client transport close attempts retain diagnostics for unexpected failures while suppressing the expected already-closed error; the log identifies the connection and close phase.

No database SQL or storage is added. The start barrier is per tunnel generation and does not add work per packet. The Proxy-side handshake synchronization addresses the observed Goetty connection-swap race for Proxy; it does not claim to fix other Goetty users.

Validation

  • Full ./pkg/proxy -race -count=1 and the selected TestChangeWatchProxy / TestProxyShutdownCancelsInFlightSQL integration tests under -race passed on 1845f66c848; the only later change adjusts test cleanup.
  • A normal SQL disconnect emits no proxy close ERROR. Injected early and final close failures remain visible with the connection ID and phase; reset and already-closed controls are covered.
  • TestTunnelStartsBothPipesBeforeQuit passed 100 race iterations after its cleanup change. A deliberately injected failure after QUIT delivery confirmed its worker is released. Earlier fast-QUIT testing also failed when the start barrier was deliberately removed.
  • Incremental SCA selected 18 affected packages and passed changed-file gofmt, repository err-check, go vet, molint and golangci-lint 2.14.0. After the test-only cleanup change, the affected ./pkg/proxy checks were repeated and passed.

Tests used Go 1.27.1 on Linux with the checkout's native libraries. CI for the updated head is pending. Goetty's separate pre-existing post-handler close diagnostic is outside the proxy close diagnostic fixed here.

@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 23, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: b2d1708bec7d79e331418327490e2ad7960950e8

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: b2d1708bec7d79e331418327490e2ad7960950e8

Assessment: request_changes

The shutdown path reuses Goetty’s handler join and preserves the existing cache handoff. The race suite and embedded SQL tests passed. One regression remains in ordinary disconnect logging.

Model: gpt-6.2-sol / xhigh

Session: 01a1ee80-0d82-7030-a965-b51f496c3054 · slot 2 · generation 1

  • P3 pkg/proxy/handler.go:291: A plaintext client disconnects normally after a successful query.
    Impact: Routine disconnects emit a misleading ERROR log. On proxies with high connection turnover, those entries can obscure genuine failures.
    Evidence: The handler closes the raw socket to unblock forwarding. After joining the workers, clientConn.Close closes the same transport again and logs the expected closed-socket error at ERROR. Matched race runs recorded four such errors for four plaintext disconnects on the candidate and zero on the merge base. Preserve the early socket close and post-join cleanup, and use the existing expected-close classifier for the second close. See receipts 1795445673864054133-2 and 1795445608599041622-2.

Validation:

  • Verified the frozen patch, pinned policy, formatting, native artifact provenance, isolation preflight, and all three discussion entries.

  • The complete Proxy race suite passed 330 root tests. Thirteen focused tests each passed 100 race repetitions. See receipt 1795445533643004999-2 and validation-audit.log.

  • TestChangeWatchProxy and TestProxyShutdownCancelsInFlightSQL passed under the race detector. The shutdown test passed two additional runs. See receipts 1795445615535763930-2 and 1795445660604440197-2.

Limitations:

  • Local validation used Linux and an embedded single-CN cluster. The frozen CI snapshot still had active lanes. This review assessed main.

@XuPeng-SH

XuPeng-SH commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 97db0d1a801728d2fd54f907e14d93b98f036604

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: 97db0d1a801728d2fd54f907e14d93b98f036604

Assessment: approve

Proxy shutdown now joins Goetty handlers and their forwarding and transfer workers before releasing shared clients. It reuses the existing cache handoff barrier and preserves disconnect cleanup for in-flight SQL. The prior logging finding is resolved. Routine plaintext disconnects emit no Proxy close ERROR, and unexpected close failures retain the connection ID and phase.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

Validation:

  • Verified the 16-file frozen diff, formatting, pinned policy, native build provenance, isolation preflight, and all five discussion entries.

  • The full Proxy race suite passed 331 tests. Fast QUIT, ordinary disconnect, and injected close failures each passed 100 race repetitions on the assigned head. Commands, receipts, and logs are indexed in validation-reconciliation.json.

  • TestChangeWatchProxy and TestProxyShutdownCancelsInFlightSQL passed under the race detector. The shutdown test verified that the active client query failed and its backend session disappeared from the process list. See isolated-race.jsonl and checks/1795449405732982918-2.json.

Limitations:

  • Local SQL validation used a Linux embedded single-CN cluster. Full CI lanes were still running in the frozen snapshot. The review covers main.

  • The matched idle-shutdown checks still observed Goetty handler and post-handler close diagnostics. Total ERROR entries decreased on the head.

This branch was successfully deployed

No deployments
ci — a7a9def4 Deployed Nov 23, 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/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants