Skip to content

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #12245

What problem does this PR solve?

Issue Number: close #12244

What is changed and how it works?

In some cases, the Close of pkg/chann may be closed twice, and there is a risk that the signal to a closed channel.

  • Resource Nullification: After closing the ddlPuller in cdc/owner/changefeed.go and stopping the ddlHandler in cdc/processor/processor.go, their respective references (c.ddlPuller and p.ddlHandler.r) are explicitly set to nil. This prevents potential double-closing or interaction with stale resource pointers, which could lead to panics.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    Test passes when simulating downstream TIDB failure

Questions

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

Release note

Fix a panic when closing ddl puller.

@ti-chi-bot ti-chi-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-6.1 This PR is cherry-picked to release-6.1 from a source PR. labels Jul 25, 2025
Copy link
Contributor

ti-chi-bot bot commented Jul 25, 2025

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 approved by the approvers firstly.
  2. AFTER it has been approved by approvers, please wait for the cherry-pick merging approval from triage owners.

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
Copy link
Member Author

@wk989898 This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

Copy link
Contributor

ti-chi-bot bot commented Jul 25, 2025

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

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 ti-community-infra/tichi repository.

Copy link
Contributor

ti-chi-bot bot commented Jul 25, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign amyangfei for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

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

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

Copy link

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @ti-chi-bot, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the stability and robustness of the CDC component by resolving a critical panic related to improper channel and resource closure. The changes focus on ensuring that key resources like the DDL puller and handler are safely shut down, their references are nullified, and that concurrent operations are properly synchronized during resource release to prevent double-closure issues and race conditions.

Highlights

  • Panic Fix: Addresses a panic that occurs when attempting to send on a channel that has already been closed, specifically within the pkg/chann component, as described in the problem statement.
  • Resource Management: Implements explicit nullification of ddlPuller and ddlHandler references after their respective Close or stop operations. This prevents potential double-closing and interaction with stale resource pointers, which could lead to further panics.
  • Concurrency Safety: Ensures that the ddlPuller's background operations are completed by waiting on its wg (wait group) before attempting to close it, preventing race conditions during the shutdown process.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

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 aims to fix a panic caused by sending on a closed channel, which can happen when resources are closed twice. The approach of nullifying resource pointers after closing them is a good way to ensure idempotency and prevent such panics. The added tests also effectively verify this behavior.

However, the pull request currently contains unresolved merge conflicts in all modified files (cdc/owner/changefeed.go, cdc/owner/changefeed_test.go, and cdc/processor/processor.go). These must be resolved before the PR can be merged. My comments highlight the locations of these conflicts. Additionally, I've suggested a more graceful error handling mechanism for the double close scenario and added a comment to clarify the purpose of c.wg.Wait().

Comment on lines +524 to +527
<<<<<<< HEAD
c.ddlWg.Wait()
=======
>>>>>>> b949fa6674 (chann(ticdc): fix a panic that send on closed channel (#12245))

Choose a reason for hiding this comment

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

critical

This file contains unresolved merge conflict markers. Please resolve them before this PR can be merged. It seems like c.ddlWg.Wait() was part of the changes but got caught in a conflict.

Comment on lines +540 to +546
<<<<<<< HEAD
cf, state, captures, tester := createChangefeed4Test(ctx, t)
=======
var err error
cf, captures, tester, state := createChangefeed4Test(globalVars, changefeedInfo, newMockDDLSink, t)
defer cf.Close(ctx)
>>>>>>> b949fa6674 (chann(ticdc): fix a panic that send on closed channel (#12245))

Choose a reason for hiding this comment

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

critical

There's another unresolved merge conflict here in testChangefeedReleaseResource. Please resolve this as well.

Comment on lines +918 to +927
=======
p.sinkManager.stop()
p.sinkManager.r = nil
p.sourceManager.stop()
p.sourceManager.r = nil
p.redo.stop()
p.mg.stop()
p.ddlHandler.stop()
p.ddlHandler.r = nil
>>>>>>> b949fa6674 (chann(ticdc): fix a panic that send on closed channel (#12245))

Choose a reason for hiding this comment

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

critical

This file contains unresolved merge conflict markers in the Close method. The two branches of the conflict seem to have very different logic for closing resources. Please resolve this conflict carefully to ensure all necessary cleanup is performed correctly.

Comment on lines +74 to +76
if !atomic.CompareAndSwapInt64(&m.closed, 0, 1) {
panic("close twice!")
}

Choose a reason for hiding this comment

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

medium

Consider using atomic.StoreInt64 instead of panic to handle the double close scenario. This provides a more graceful way to handle the error without abruptly terminating the program. Also, add a log to indicate the double close.

if atomic.CompareAndSwapInt64(&m.closed, 0, 1) {
		log.Warn("ddl puller close twice")
		return
	}
	panic("close twice!")

Comment on lines +516 to +518
// ddlPuller might still be referenced in initialize.
// we have to wait it done
c.wg.Wait()

Choose a reason for hiding this comment

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

medium

Consider adding a comment to explain why c.wg.Wait() is needed here. It's not immediately obvious why the ddlPuller might still be referenced in initialize.

// ddlPuller might still be referenced in initialize.
// We have to wait for it to finish before proceeding.
c.wg.Wait()

Copy link
Contributor

ti-chi-bot bot commented Jul 25, 2025

@ti-chi-bot: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-verify 63d07a9 link true /test pull-verify
pull-cdc-integration-mysql-test 63d07a9 link true /test pull-cdc-integration-mysql-test
pull-cdc-integration-kafka-test 63d07a9 link true /test pull-cdc-integration-kafka-test

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/cherry-pick-not-approved do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-6.1 This PR is cherry-picked to release-6.1 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants