Skip to content
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

changefeed(ticdc): check changefeed info is nil to prevent panic (#9917) #9923

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/upstream/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ func (m *Manager) Tick(ctx context.Context,

activeUpstreams := make(map[uint64]struct{})
for _, cf := range globalState.Changefeeds {
activeUpstreams[cf.Info.UpstreamID] = struct{}{}
if cf != nil && cf.Info != nil {
activeUpstreams[cf.Info.UpstreamID] = struct{}{}
}
}
m.mu.Lock()
defer m.mu.Unlock()
Expand Down
15 changes: 11 additions & 4 deletions pkg/upstream/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,23 @@ func TestUpstream(t *testing.T) {
require.NotNil(t, up)

// test Tick
_ = manager.Tick(context.Background(), &orchestrator.GlobalReactorState{})
globalState := &orchestrator.GlobalReactorState{
Changefeeds: make(map[model.ChangeFeedID]*orchestrator.ChangefeedReactorState),
}
// add one changefeed state whose info is nil to make sure it won't be checked
globalState.Changefeeds[model.DefaultChangeFeedID("1")] = &orchestrator.ChangefeedReactorState{
Info: nil,
}
_ = manager.Tick(context.Background(), globalState)
mockClock.Add(maxIdleDuration * 2)
manager.lastTickTime = atomic.Time{}
_ = manager.Tick(context.Background(), &orchestrator.GlobalReactorState{})
_ = manager.Tick(context.Background(), globalState)
// wait until up2 is closed
for !up2.IsClosed() {
}
manager.lastTickTime = atomic.Time{}
_ = manager.Tick(context.Background(), &orchestrator.GlobalReactorState{})
_ = manager.Tick(context.Background(), &orchestrator.GlobalReactorState{})
_ = manager.Tick(context.Background(), globalState)
_ = manager.Tick(context.Background(), globalState)
up, ok = manager.Get(testID)
require.False(t, ok)
require.Nil(t, up)
Expand Down