diff --git a/pkg/server/conn.go b/pkg/server/conn.go index 3a61e31f06d56..ee9566dea4448 100644 --- a/pkg/server/conn.go +++ b/pkg/server/conn.go @@ -2050,7 +2050,11 @@ func (cc *clientConn) handleStmt(ctx context.Context, stmt ast.StmtNode, warns [ execStmt.(*executor.ExecStmt).FinishExecuteStmt(0, err, false) } } - return false, err + if err != nil { + return false, err + } + + return false, nil } func (cc *clientConn) handleFileTransInConn(ctx context.Context, status uint16) (bool, error) { @@ -2278,9 +2282,6 @@ func (cc *clientConn) writeChunks(ctx context.Context, rs resultset.ResultSet, b stmtDetail.WriteSQLRespDuration += time.Since(start) } } - if err := rs.Close(); err != nil { - return false, err - } if stmtDetail != nil { start = time.Now() diff --git a/pkg/session/session.go b/pkg/session/session.go index 715a29a3a8fd1..c405a6b26e5a0 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -2475,20 +2475,16 @@ const ExecStmtVarKey ExecStmtVarKeyType = 0 // RecordSet, so this struct exists and RecordSet.Close() is overrided handle that. type execStmtResult struct { sqlexec.RecordSet - se *session - sql sqlexec.Statement - closed bool + se *session + sql sqlexec.Statement } func (rs *execStmtResult) Close() error { - if rs.closed { - return nil - } se := rs.se - err := rs.RecordSet.Close() - err = finishStmt(context.Background(), se, err, rs.sql) - rs.closed = true - return err + if err := rs.RecordSet.Close(); err != nil { + return finishStmt(context.Background(), se, err, rs.sql) + } + return finishStmt(context.Background(), se, nil, rs.sql) } // rollbackOnError makes sure the next statement starts a new transaction with the latest InfoSchema.