-
Notifications
You must be signed in to change notification settings - Fork 293
chann(ticdc): fix a panic that send on closed channel (#12245) #12260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release-6.1
Are you sure you want to change the base?
chann(ticdc): fix a panic that send on closed channel (#12245) #12260
Conversation
Signed-off-by: ti-chi-bot <[email protected]>
This cherry pick PR is for a release branch and has not yet been approved by triage owners. To merge this cherry pick:
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. |
@wk989898 This PR has conflicts, I have hold it. |
@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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
There was a problem hiding this 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
andddlHandler
references after their respectiveClose
orstop
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 itswg
(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
-
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. ↩
There was a problem hiding this 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()
.
<<<<<<< HEAD | ||
c.ddlWg.Wait() | ||
======= | ||
>>>>>>> b949fa6674 (chann(ticdc): fix a panic that send on closed channel (#12245)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<<<<<<< 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
======= | ||
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !atomic.CompareAndSwapInt64(&m.closed, 0, 1) { | ||
panic("close twice!") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!")
// ddlPuller might still be referenced in initialize. | ||
// we have to wait it done | ||
c.wg.Wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ti-chi-bot: The following tests failed, say
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. |
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
ofpkg/chann
may be closed twice, and there is a risk that the signal to a closed channel.Check List
Tests
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