Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server,session: make sure ResultSet.Close() errors return to the client (#48447) #48483

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions server/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
16 changes: 10 additions & 6 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down