diff --git a/ttl/session/session.go b/ttl/session/session.go index 9a7b115eb4ea9..d07419651a103 100644 --- a/ttl/session/session.go +++ b/ttl/session/session.go @@ -107,8 +107,8 @@ func (s *session) RunInTxn(ctx context.Context, fn func() error) (err error) { success := false defer func() { if !success { - _, err = s.ExecuteSQL(ctx, "ROLLBACK") - terror.Log(err) + _, rollbackErr := s.ExecuteSQL(ctx, "ROLLBACK") + terror.Log(rollbackErr) } }() diff --git a/ttl/session/session_test.go b/ttl/session/session_test.go index a30949206223a..ecabbc8683158 100644 --- a/ttl/session/session_test.go +++ b/ttl/session/session_test.go @@ -39,10 +39,11 @@ func TestSessionRunInTxn(t *testing.T) { })) tk2.MustQuery("select * from t order by id asc").Check(testkit.Rows("1 10")) - require.NoError(t, se.RunInTxn(context.TODO(), func() error { + err := se.RunInTxn(context.TODO(), func() error { tk.MustExec("insert into t values (2, 20)") - return errors.New("err") - })) + return errors.New("mockErr") + }) + require.EqualError(t, err, "mockErr") tk2.MustQuery("select * from t order by id asc").Check(testkit.Rows("1 10")) require.NoError(t, se.RunInTxn(context.TODO(), func() error {