From 374802cf0706b7e62d02d71a2e81c5d2422383e8 Mon Sep 17 00:00:00 2001 From: amyangfei Date: Thu, 2 Mar 2023 22:52:02 +0800 Subject: [PATCH] use defer cancel --- cdc/sink/dmlsink/txn/mysql/mysql.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cdc/sink/dmlsink/txn/mysql/mysql.go b/cdc/sink/dmlsink/txn/mysql/mysql.go index d94f3348570..f9a9c7fc261 100644 --- a/cdc/sink/dmlsink/txn/mysql/mysql.go +++ b/cdc/sink/dmlsink/txn/mysql/mysql.go @@ -615,7 +615,8 @@ func (s *mysqlBackend) multiStmtExecute( } multiStmtArgs = append(multiStmtArgs, dmls.values[i]...) } - ctx, cancelFunc := context.WithTimeout(ctx, writeTimeout) + ctx, cancel := context.WithTimeout(ctx, writeTimeout) + defer cancel() _, execError := tx.ExecContext(ctx, multiStmtSQL, multiStmtArgs...) if execError != nil { err := logDMLTxnErr( @@ -626,10 +627,8 @@ func (s *mysqlBackend) multiStmtExecute( log.Warn("failed to rollback txn", zap.Error(rbErr)) } } - cancelFunc() return err } - cancelFunc() return nil }