From b4f1aecbad63768fdf11fa58cd893536cc4e96c0 Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Fri, 5 Mar 2021 13:00:38 +0800 Subject: [PATCH] cherry pick #1477 to release-2.0 (#1481) Signed-off-by: ti-srebot Co-authored-by: lance6716 --- pkg/conn/basedb.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/conn/basedb.go b/pkg/conn/basedb.go index 7ca372259c..8112210f76 100644 --- a/pkg/conn/basedb.go +++ b/pkg/conn/basedb.go @@ -29,6 +29,7 @@ import ( "github.com/pingcap/dm/dm/config" "github.com/pingcap/dm/pkg/retry" "github.com/pingcap/dm/pkg/terror" + "github.com/pingcap/dm/pkg/utils" "github.com/go-sql-driver/mysql" toolutils "github.com/pingcap/tidb-tools/pkg/utils" @@ -112,7 +113,9 @@ func (d *DefaultDBProviderImpl) Apply(config config.DBConfig) (*BaseDB, error) { mockDB.ExpectClose() }) - err = db.Ping() + ctx, cancel := context.WithTimeout(context.Background(), utils.DefaultDBTimeout) + defer cancel() + err = db.PingContext(ctx) failpoint.Inject("failDBPing", func(_ failpoint.Value) { err = errors.New("injected error") })