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

executor: fix forget to release session (#56299) #56342

Merged
Merged
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
1 change: 0 additions & 1 deletion pkg/executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ go_library(
"@com_github_burntsushi_toml//:toml",
"@com_github_docker_go_units//:go-units",
"@com_github_gogo_protobuf//proto",
"@com_github_ngaut_pools//:pools",
"@com_github_opentracing_basictracer_go//:basictracer-go",
"@com_github_opentracing_opentracing_go//:opentracing-go",
"@com_github_pingcap_errors//:errors",
Expand Down
15 changes: 2 additions & 13 deletions pkg/executor/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"syscall"
"time"

"github.com/ngaut/pools"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/ddl/placement"
Expand Down Expand Up @@ -119,16 +118,6 @@ type userInfo struct {
authString string
}

// 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, _ *chunk.Chunk) (err error) {
if e.done {
Expand Down Expand Up @@ -1718,10 +1707,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 @@ -2439,10 +2428,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