diff --git a/loader/checkpoint.go b/loader/checkpoint.go index ab7d8a65ea..2d83376fa6 100644 --- a/loader/checkpoint.go +++ b/loader/checkpoint.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/dm/dm/config" "github.com/pingcap/dm/pkg/conn" tcontext "github.com/pingcap/dm/pkg/context" + "github.com/pingcap/dm/pkg/log" "github.com/pingcap/dm/pkg/terror" "go.uber.org/zap" @@ -296,8 +297,14 @@ func (cp *RemoteCheckPoint) Init(filename string, endPos int64) error { // Close implements CheckPoint.Close func (cp *RemoteCheckPoint) Close() { - cp.conn.Close() - cp.db.Close() + err := cp.conn.Close() + if err != nil { + cp.tctx.L().Error("close checkpoint connection error", log.ShortError(err)) + } + err = cp.db.Close() + if err != nil { + cp.tctx.L().Error("close checkpoint db error", log.ShortError(err)) + } } // GenSQL implements CheckPoint.GenSQL diff --git a/loader/loader.go b/loader/loader.go index cd489f9133..8404661d64 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -559,7 +559,10 @@ func (l *Loader) Close() { } l.stopLoad() - l.toDB.Close() + err := l.toDB.Close() + if err != nil { + l.tctx.L().Error("close toDB error", log.ShortError(err)) + } l.checkPoint.Close() l.closed.Set(true) } diff --git a/syncer/checkpoint.go b/syncer/checkpoint.go index 82ec37dc69..497fd1b11a 100644 --- a/syncer/checkpoint.go +++ b/syncer/checkpoint.go @@ -498,7 +498,11 @@ func (cp *RemoteCheckPoint) createTable() error { func (cp *RemoteCheckPoint) Load() error { query := fmt.Sprintf("SELECT `cp_schema`, `cp_table`, `binlog_name`, `binlog_pos`, `is_global` FROM `%s`.`%s` WHERE `id`='%s'", cp.schema, cp.table, cp.id) rows, err := cp.dbConn.querySQL(cp.tctx, query) - defer rows.Close() + defer func() { + if rows != nil { + rows.Close() + } + }() failpoint.Inject("LoadCheckpointFailed", func(val failpoint.Value) { err = tmysql.NewErr(uint16(val.(int)))