Skip to content

Commit

Permalink
server,session: make sure ResultSet.Close() errors return to the clie…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Nov 9, 2023
1 parent 7eb6e61 commit 24c7f8c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
9 changes: 4 additions & 5 deletions pkg/server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2049,11 +2049,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) handleFileTransInConn(ctx context.Context, status uint16) (bool, error) {
Expand Down Expand Up @@ -2285,6 +2281,9 @@ 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()
Expand Down
16 changes: 10 additions & 6 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2475,16 +2475,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.
Expand Down

0 comments on commit 24c7f8c

Please sign in to comment.