Skip to content

owner(ticdc): close the ddl sink to fix the resource leak#12678

Open
3AceShowHand wants to merge 1 commit into
pingcap:release-7.5from
3AceShowHand:ddl-sink-leak-fix-7.5
Open

owner(ticdc): close the ddl sink to fix the resource leak#12678
3AceShowHand wants to merge 1 commit into
pingcap:release-7.5from
3AceShowHand:ddl-sink-leak-fix-7.5

Conversation

@3AceShowHand

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: ref #12666

What is changed and how it works?

  • close the ddl sink
  • remove verbose and low informative logs

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Questions

Will it cause performance regression or break compatibility?
Do you need to update user documentation, design documentation or monitoring documentation?

Release note

close the kafka ddl sink to fix the resource leak

@ti-chi-bot

ti-chi-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This cherry pick PR is for a release branch and has not yet been approved by triage owners.
Adding the do-not-merge/cherry-pick-not-approved label.

To merge this cherry pick:

  1. It must be LGTMed and approved by the reviewers firstly.
  2. For pull requests to TiDB-x branches, it must have no failed tests.
  3. AFTER it has lgtm and approved labels, please wait for the cherry-pick merging approval from triage owners.
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/cherry-pick-not-approved size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 5, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request removes a noisy log statement in shared_client.go and updates ddl_sink.go to properly close the DDL sink before setting it to nil during retries. However, a potential data race and nil-pointer panic was identified in ddl_sink.go because s.sink is accessed and modified concurrently without synchronization; introducing a mutex is recommended to protect these operations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread cdc/owner/ddl_sink.go
Comment on lines +177 to +182
if s.sink != nil {
s.sink.Close()
s.sink = nil
log.Info("close the ddl sink, rebuild it when trying again",
zap.String("namespace", s.changefeedID.Namespace), zap.String("changefeed", s.changefeedID.ID))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Potential Data Race and Nil-Pointer Panic on s.sink\n\nThere is a potential concurrency issue where s.sink is accessed and modified without proper synchronization:\n1. The Race: s.sink is read/written concurrently by the background loop (via retrySinkAction and makeSinkReady) and other goroutines (such as emitBootstrap which calls makeSinkReady and then s.sink.WriteDDLEvent).\n2. The Panic: If retrySinkAction encounters an error, it closes the sink and sets s.sink = nil (lines 178-179). If emitBootstrap is running concurrently, it might check that s.sink is not nil (or initialize it via makeSinkReady), but before it can call s.sink.WriteDDLEvent, retrySinkAction sets s.sink = nil, leading to a nil-pointer dereference and panic.\n\n### Recommendation\nIntroduce a mutex (e.g., sinkMu sync.Mutex) in ddlSinkImpl to protect all read, write, and close operations on s.sink across makeSinkReady, retrySinkAction, close, and emitBootstrap.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should fix the race condition thing with an atomic pointer in a separate PR, since this piece of code is just copied from master branch.

@ti-chi-bot

ti-chi-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kennytm

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 5, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

[LGTM Timeline notifier]

Timeline:

  • 2026-06-05 05:53:14.821695937 +0000 UTC m=+507295.892013317: ☑️ agreed by kennytm.

@ti-chi-bot ti-chi-bot Bot added the approved label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved do-not-merge/cherry-pick-not-approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants