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

owner: fix mem leak in changefeed #942

Merged
merged 4 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix mem leak in changefeed
  • Loading branch information
leoppro committed Sep 9, 2020
commit e4ebd5668b697456e58995ed8186a5f19258d208
12 changes: 12 additions & 0 deletions cdc/changefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -846,3 +846,15 @@ func (c *changeFeed) pullDDLJob() error {
}
return nil
}

func (c *changeFeed) Close() {
err := c.ddlHandler.Close()
if err != nil {
log.Warn("failed to close ddl handler", zap.Error(err))
}
err = c.sink.Close()
if err != nil {
log.Warn("failed to close owner sink", zap.Error(err))
}
log.Info("changefeed closed", zap.String("id", c.id))
}
8 changes: 2 additions & 6 deletions cdc/owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/pingcap/ticdc/pkg/cyclic/mark"
cerror "github.com/pingcap/ticdc/pkg/errors"
"github.com/pingcap/ticdc/pkg/filter"
"github.com/pingcap/ticdc/pkg/logutil"
"github.com/pingcap/ticdc/pkg/scheduler"
"github.com/pingcap/ticdc/pkg/security"
"github.com/pingcap/ticdc/pkg/util"
Expand Down Expand Up @@ -497,6 +496,7 @@ func (o *Owner) loadChangeFeeds(ctx context.Context) error {
// don't need to return an error.
log.Warn("create changefeed failed, retry later",
zap.String("changefeed", changeFeedID), zap.Error(err))
newCf.Close()
continue
}
o.changeFeeds[changeFeedID] = newCf
Expand Down Expand Up @@ -643,11 +643,7 @@ func (o *Owner) dispatchJob(ctx context.Context, job model.AdminJob) error {
if err != nil {
return errors.Trace(err)
}
// TODO Closing the resource should not be here
err = cf.ddlHandler.Close()
log.Info("stop changefeed ddl handler", zap.String("changefeed id", job.CfID), logutil.ZapErrorFilter(err, context.Canceled))
err = cf.sink.Close()
log.Info("stop changefeed sink", zap.String("changefeed id", job.CfID), logutil.ZapErrorFilter(err, context.Canceled))
cf.Close()
// Only need to process stoppedFeeds with `AdminStop` command here.
// For `AdminResume`, we remove stopped feed in changefeed initialization phase.
// For `AdminRemove`, we need to update stoppedFeeds when removing a stopped changefeed.
Expand Down