From 3b1327ee17db59dd3007a83ebafa6886b0c6d5d5 Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Thu, 9 Nov 2023 17:54:49 +0800 Subject: [PATCH] This is an automated cherry-pick of #48447 Signed-off-by: ti-chi-bot --- server/conn.go | 22 +++++++++++++++++----- session/session.go | 16 ++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/server/conn.go b/server/conn.go index 2f0e0b6d3335a..f56ab7b950996 100644 --- a/server/conn.go +++ b/server/conn.go @@ -2053,11 +2053,7 @@ func (cc *clientConn) handleStmt(ctx context.Context, stmt ast.StmtNode, warns [ execStmt.(*executor.ExecStmt).FinishExecuteStmt(0, err, false) } } - if err != nil { - return false, err - } - - return false, nil + return false, err } func (cc *clientConn) handleQuerySpecial(ctx context.Context, status uint16) (bool, error) { @@ -2250,7 +2246,23 @@ func (cc *clientConn) writeChunks(ctx context.Context, rs ResultSet, binary bool stmtDetail.WriteSQLRespDuration += time.Since(start) } } +<<<<<<< HEAD:server/conn.go return false, cc.writeEOF(serverStatus) +======= + if err := rs.Close(); err != nil { + return false, err + } + + if stmtDetail != nil { + start = time.Now() + } + + err := cc.writeEOF(ctx, serverStatus) + if stmtDetail != nil { + stmtDetail.WriteSQLRespDuration += time.Since(start) + } + return false, err +>>>>>>> 24c7f8c39b3 (server,session: make sure ResultSet.Close() errors return to the client (#48447)):pkg/server/conn.go } // writeChunksWithFetchSize writes data from a Chunk, which filled data by a ResultSet, into a connection. diff --git a/session/session.go b/session/session.go index 25a3f05441352..189576c3a6d1c 100644 --- a/session/session.go +++ b/session/session.go @@ -2164,16 +2164,20 @@ 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 + se *session + sql sqlexec.Statement + closed bool } func (rs *execStmtResult) Close() error { - se := rs.se - if err := rs.RecordSet.Close(); err != nil { - return finishStmt(context.Background(), se, err, rs.sql) + if rs.closed { + return nil } - return finishStmt(context.Background(), se, nil, rs.sql) + se := rs.se + err := rs.RecordSet.Close() + err = finishStmt(context.Background(), se, err, rs.sql) + rs.closed = true + return err } // rollbackOnError makes sure the next statement starts a new transaction with the latest InfoSchema.