Skip to content

Commit

Permalink
server(ticdc): fix panic issue if capture is not initialized (#9746)
Browse files Browse the repository at this point in the history
close #9745
  • Loading branch information
sdojjy authored Sep 18, 2023
1 parent d0a9a4b commit 3694aa7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cdc/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ func (s *server) run(ctx context.Context) (err error) {
// Drain removes tables in the current TiCDC instance.
// It's part of graceful shutdown, should be called before Close.
func (s *server) Drain() <-chan struct{} {
if s.capture == nil {
done := make(chan struct{})
close(done)
return done
}
return s.capture.Drain()
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ func (o *options) run(cmd *cobra.Command) error {
return errors.Trace(err)
}
// Drain the server before shutdown.
shutdownNotify := func() <-chan struct{} { return server.Drain() }
util.InitSignalHandling(shutdownNotify, cancel)
util.InitSignalHandling(server.Drain, cancel)

// Run TiCDC server.
err = server.Run(ctx)
Expand Down

0 comments on commit 3694aa7

Please sign in to comment.