Skip to content

Commit

Permalink
*: fix slow query nil pointer panic when get session for TTL (#39865)
Browse files Browse the repository at this point in the history
close #39864
  • Loading branch information
lcwangchao committed Dec 13, 2022
1 parent 621115b commit b7e21a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
if a.retryCount > 0 {
slowItems.ExecRetryTime = costTime - sessVars.DurationParse - sessVars.DurationCompile - time.Since(a.retryStartTime)
}
if _, ok := a.StmtNode.(*ast.CommitStmt); ok {
if _, ok := a.StmtNode.(*ast.CommitStmt); ok && sessVars.PrevStmt != nil {
slowItems.PrevStmt = sessVars.PrevStmt.String()
}
slowLog := sessVars.SlowLogFormat(slowItems)
Expand Down
3 changes: 2 additions & 1 deletion ttl/ttlworker/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func getSession(pool sessionPool) (session.Session, error) {
pool.Put(resource)
})

if _, err = se.ExecuteSQL(context.Background(), "commit"); err != nil {
// Force rollback the session to guarantee the session is not in any explicit transaction
if _, err = se.ExecuteSQL(context.Background(), "ROLLBACK"); err != nil {
se.Close()
return nil, err
}
Expand Down

0 comments on commit b7e21a0

Please sign in to comment.