-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -513,11 +513,18 @@ | |
|
||
c.cancel() | ||
c.cancel = func() {} | ||
// ddlPuller might still be referenced in initialize. | ||
// we have to wait it done | ||
c.wg.Wait() | ||
|
||
if c.ddlPuller != nil { | ||
c.ddlPuller.Close() | ||
c.ddlPuller = nil | ||
} | ||
<<<<<<< HEAD | ||
c.ddlWg.Wait() | ||
======= | ||
>>>>>>> b949fa6674 (chann(ticdc): fix a panic that send on closed channel (#12245)) | ||
Comment on lines
+524
to
+527
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if c.sink != nil { | ||
canceledCtx, cancel := context.WithCancel(context.Background()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"os" | ||
"path/filepath" | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -42,6 +43,7 @@ import ( | |
|
||
type mockDDLPuller struct { | ||
// DDLPuller | ||
<<<<<<< HEAD | ||
resolvedTs model.Ts | ||
ddlQueue []*timodel.Job | ||
} | ||
|
@@ -51,6 +53,12 @@ func (m *mockDDLPuller) FrontDDL() (uint64, *timodel.Job) { | |
return m.ddlQueue[0].BinlogInfo.FinishedTS, m.ddlQueue[0] | ||
} | ||
return m.resolvedTs, nil | ||
======= | ||
resolvedTs model.Ts | ||
ddlQueue []*timodel.Job | ||
schemaStorage entry.SchemaStorage | ||
closed int64 | ||
>>>>>>> b949fa6674 (chann(ticdc): fix a panic that send on closed channel (#12245)) | ||
} | ||
|
||
func (m *mockDDLPuller) PopFrontDDL() (uint64, *timodel.Job) { | ||
|
@@ -62,7 +70,11 @@ func (m *mockDDLPuller) PopFrontDDL() (uint64, *timodel.Job) { | |
return m.resolvedTs, nil | ||
} | ||
|
||
func (m *mockDDLPuller) Close() {} | ||
func (m *mockDDLPuller) Close() { | ||
if !atomic.CompareAndSwapInt64(&m.closed, 0, 1) { | ||
panic("close twice!") | ||
} | ||
Comment on lines
+74
to
+76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using if atomic.CompareAndSwapInt64(&m.closed, 0, 1) {
log.Warn("ddl puller close twice")
return
}
panic("close twice!") |
||
} | ||
|
||
func (m *mockDDLPuller) Run(ctx cdcContext.Context) error { | ||
<-ctx.Done() | ||
|
@@ -525,7 +537,13 @@ func testChangefeedReleaseResource( | |
redoLogDir string, | ||
expectedInitialized bool, | ||
) { | ||
<<<<<<< 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)) | ||
Comment on lines
+540
to
+546
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// pre check | ||
cf.Tick(ctx, state, captures) | ||
|
@@ -1050,3 +1068,25 @@ func TestBarrierAdvance(t *testing.T) { | |
require.Equal(t, mockDDLPuller.resolvedTs, barrier) | ||
} | ||
} | ||
|
||
func TestReleaseResourcesTwice(t *testing.T) { | ||
globalVars, changefeedInfo := vars.NewGlobalVarsAndChangefeedInfo4Test() | ||
ctx := context.Background() | ||
cf, captures, tester, state := createChangefeed4Test(globalVars, changefeedInfo, newMockDDLSink, t) | ||
defer cf.Close(ctx) | ||
|
||
// pre check | ||
state.CheckCaptureAlive(globalVars.CaptureInfo.ID) | ||
require.False(t, preflightCheck(state, captures)) | ||
tester.MustApplyPatches() | ||
|
||
// initialize | ||
cf.Tick(ctx, state.Info, state.Status, captures) | ||
tester.MustApplyPatches() | ||
require.Equal(t, cf.initialized.Load(), true) | ||
|
||
// close twice | ||
cf.releaseResources(ctx) | ||
cf.isReleased = false | ||
cf.releaseResources(ctx) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -905,6 +905,7 @@ | |
// when error occurs during closing the processor | ||
p.cleanupMetrics() | ||
|
||
<<<<<<< HEAD | ||
for _, tbl := range p.tables { | ||
tbl.Cancel() | ||
} | ||
|
@@ -914,6 +915,16 @@ | |
p.cancel() | ||
p.wg.Wait() | ||
p.upStream.Release() | ||
======= | ||
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)) | ||
Comment on lines
+918
to
+927
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
if p.agent == nil { | ||
return nil | ||
|
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 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.