Skip to content

fix: cancel stale logtail subscription pulls on disconnect - #29361

Merged
XuPeng-SH merged 6 commits into
mainfrom
codex/issue-29275-logtail-recovery
Sep 25, 2026
Merged

XuPeng-SH merged 6 commits into
mainfrom
codex/issue-29275-logtail-recovery

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • API-change
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #29275. This is a partial mitigation and intentionally does not close the issue.

What this PR does / why we need it:

TN subscription pulls previously inherited the logtail server lifetime rather than the transport session lifetime. After a CN disconnected, old-generation pulls could continue collecting a large catalog logtail and occupy pull capacity even though their response had no live recipient.

Tie both pull phases to the session context while preserving caller/server cancellation. Reject admission from a closed session, release phase-1 tails if their session closes before handoff, and release a callback exactly once if a context-ignoring collector returns success after cancellation. Generation checks remain in place.

Controlled tests cover transport-disconnect cancellation of an active pull, closed-session admission, and late successful phase-1/phase-2 callbacks. This change does not adjust the CN's ~30s forced-subscribe wait or TN's collection timeout, and it cannot interrupt WaitUntilCommitted while that lower-level wait ignores context. It therefore does not establish that the historical 185s pause/98 query failures are fully fixed; a representative large-catalog recovery validation and aligned budget/context-aware wait work remain under #29275.

Validation: make cgo; targeted logtail service tests, full owning package tests, race-targeted tests, go vet ./pkg/vm/engine/tae/logtail/service, git diff --check. GPT-6 medium design and lifecycle review completed.

@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 requested a review from aptend as a code owner September 24, 2026 12:15
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 24, 2026
@mergify mergify Bot added kind/bug Something isn't working kind/enhancement kind/test-ci labels Sep 24, 2026

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

Deep review of ab883b4abceb27a3af2c77ca80897a4c7b3e1c9c against PR base a61e7710e26c7d7613e2aa19913460ff9b7e2606.

No blocking production finding for the stated partial mitigation. One non-blocking test-cleanup comment is attached.

Reviewed both changed files and traced request admission, both collection phases, phase-1 queue ownership, response merging/release, session transport cancellation, server shutdown, and generation-aware completion/unregistration.

Contract Review result
Callback ownership Error/late-success collection releases its callback; a cancelled phase-1 handoff releases its tail; phase-2 failure releases phase 1; successful merge transfers both callbacks to response cleanup.
Cancellation and generations The session now owns collection cancellation while the caller remains connected through AfterFunc. Deferred unregister remains generation guarded. A cancelled transport cannot activate a newer subscription through an old completion.
Cost and boundedness The added context/AfterFunc work is per pull phase, with deferred cancellation/detachment and the existing worker/queue bounds; no row-level work or new retry framework.

Evidence reused: CI run 35997966889, attempt 2 completed successfully at this head. The UT summary artifact's checkpoint log explicitly includes pkg/vm/engine/tae/logtail/service in the light -race -short -tags matrixone_test package set, and that stage completed with status 0. Coverage, SCA and enabled BVT checks are also green. Review worktree is clean; diff check passed. No redundant local full-suite rerun was needed.

The issue boundary is correctly documented: lower WaitUntilCommitted still ignores context, and this change does not align the CN/TN recovery budgets or validate the historical large-catalog 185s pause. Keep #29275 open; those are follow-up obligations, not claims established by this PR.

COMMENT because the authenticated reviewer is also the PR author.

logtailer := &controlledLogtailer{
tableFn: func(_ context.Context, table api.TableID, _, to timestamp.Timestamp) (logtail.TableLogtail, func(), error) {
close(entered)
<-release // Deliberately return success after the transport is closed.

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.

[P3] Release and join the controlled collector on every test exit

The collector intentionally ignores context while waiting on release, but the channel is closed only on the normal path at line 199. If the entry watchdog fires just before the collector is scheduled, t.Fatal runs the session/server cleanups while the collector can still enter and block forever on this receive. This goroutine calls getSubLogtailPhase directly, so it is not joined by server.pullWorkers during Close.

Register an idempotent barrier release immediately and a bounded join for the launched goroutine, with cleanup ordering that releases it before tearing down its dependencies. This is non-blocking test hygiene; the normal success path and production cancellation logic look sound.

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.

Fixed in a06ac06: an idempotent cleanup now releases the barrier and joins the goroutine before session/server teardown. Both phase subtests passed 10 runs in normal and race modes; owning package and go vet passed.

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

Deep review of e03a1017a999440db1f62d606893ce5845d21dc7 against the PR base and merge-base e914d987641c266162eb607ec072fdb5a2b06da9. I reviewed all three changed files and rechecked the earlier review's lifecycle finding after the new test and main merge.

Decision: no blocking finding for the stated partial mitigation; recommend merging with #29275 kept open. This account is also the PR author, so GitHub receives a COMMENT review rather than an approval.

Closure Finding
Admission and repeated reconnect Closed-session admission is rejected before queue handoff. The new one-worker regression exercises old transport cancellation, worker-slot release, a new transport's pull, and the old/new active subscription states. The bounded request queue can still hold stale entries briefly, but each reaches the session-cancel check before collection.
Q1: callback ownership A late successful collector result after cancellation releases its callback. Phase-1 cancellation before queue handoff releases its tail; phase-2 failure releases phase 1; successful merge transfers both callbacks to response cleanup. Generation-aware unregister prevents an old attempt from removing a newer registration. The earlier test-cleanup comment is fixed: the context-ignoring callback barrier is now released and joined before session/server cleanup, including on early assertion failure.
Q2: termination The new context is canceled by either session closure, caller cancellation, or timeout, with AfterFunc detached on return. Collectors that honor it exit and free the worker. BoundTableOperator.Run -> WaitUntilCommitted -> GetTxnState(true) still ignores context, so this PR cannot guarantee that every historical large-catalog pull relinquishes a worker before the CN's ~30s retry budget. This is a documented, unclosed #29275 follow-up, not a newly introduced regression.
Q3: bounds Request, phase-1, and worker queues remain bounded (100, 300, configured pool size). Context/timer/callback registration is one per pull phase and is canceled/detached. No new retained per-table cache or retry loop was added.
Performance / scope One extra context and cancellation hook per subscription phase, plus one cheap session-state check at admission/handoff; no per-object or per-row work changed. Existing long waits remain the dominant unresolved risk. The fix reuses current lifecycle and response ownership code without a new framework.

The new controlled worker-slot test is an appropriate deterministic oracle for context-aware collection. It is not a representative test of the context-ignoring catalog wait or a proof that the incident's 185s transaction pause/98 failed queries are fixed. Keep the PR's partial-mitigation wording and continue the context-aware wait/budget and large-catalog validation under #29275. No design gate is triggered by this focused lifecycle fix.

Validation: exact-head CI run 36080835488, attempt 2 completed successfully (UT, coverage, ARM64 SCA and enabled multi-CN BVT). Independently ran the four changed subscription tests under -race -count=3 with provenance-verified native artifacts; terminal result ok .../logtail/service 1.197s. The PR diff passes git diff --check; review checkout is clean. Main has moved since the PR base, but the affected logtail service, operator, and catalog wait files are unchanged in that interval.

@XuPeng-SH
XuPeng-SH merged commit 535ed85 into main Sep 25, 2026
25 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue-29275-logtail-recovery branch September 25, 2026 02:23

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 kind/enhancement kind/test-ci 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