Skip to content

Commit

Permalink
executor: fix forget to release session (#56299) (#57035)
Browse files Browse the repository at this point in the history
close #56271
  • Loading branch information
ti-chi-bot authored Nov 1, 2024
1 parent 8c604da commit 701b2a2
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ func (e *baseExecutor) releaseSysSession(ctx context.Context, sctx sessionctx.Co
sysSessionPool.Put(sctx.(pools.Resource))
}

// clearSysSession close the session does not return the session.
// Since the environment variables in the session are changed, the session object is not returned.
func clearSysSession(ctx context.Context, sctx sessionctx.Context) {
if sctx == nil {
return
}
_, _ = sctx.(sqlexec.SQLExecutor).ExecuteInternal(ctx, "rollback")
sctx.(pools.Resource).Close()
}

// Next implements the Executor Next interface.
func (e *SimpleExec) Next(ctx context.Context, req *chunk.Chunk) (err error) {
if e.done {
Expand Down Expand Up @@ -1735,10 +1725,10 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
}

sysSession, err := e.getSysSession()
defer clearSysSession(ctx, sysSession)
if err != nil {
return err
}
defer e.releaseSysSession(ctx, sysSession)
sqlExecutor := sysSession.(sqlexec.SQLExecutor)
// session isolation level changed to READ-COMMITTED.
// When tidb is at the RR isolation level, executing `begin` will obtain a consistent state.
Expand Down Expand Up @@ -2455,10 +2445,10 @@ func userExistsInternal(ctx context.Context, sqlExecutor sqlexec.SQLExecutor, na
func (e *SimpleExec) executeSetPwd(ctx context.Context, s *ast.SetPwdStmt) error {
ctx = kv.WithInternalSourceType(ctx, kv.InternalTxnPrivilege)
sysSession, err := e.getSysSession()
defer clearSysSession(ctx, sysSession)
if err != nil {
return err
}
defer e.releaseSysSession(ctx, sysSession)

sqlExecutor := sysSession.(sqlexec.SQLExecutor)
// session isolation level changed to READ-COMMITTED.
Expand Down

0 comments on commit 701b2a2

Please sign in to comment.