Skip to content

Commit

Permalink
[Cherry-pick] Fix nil pointer in RoutineManager.Closed() (#17036)
Browse files Browse the repository at this point in the history
move debug log to ses != nil block

Approved by: @daviszhen, @sukki37
  • Loading branch information
ck89119 authored Jun 20, 2024
1 parent 36cfc3c commit f27a435
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions pkg/frontend/routine_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,31 +296,34 @@ func (rm *RoutineManager) Created(rs goetty.IOSession) {
When the io is closed, the Closed will be called.
*/
func (rm *RoutineManager) Closed(rs goetty.IOSession) {
ses := rm.getRoutine(rs).getSession()
ses.Debugf(rm.getCtx(), "clean resource of the connection %d:%s", rs.ID(), rs.RemoteAddress())
rt := rm.deleteRoutine(rs)
if rt == nil {
return
}

defer func() {
v2.CloseRoutineCounter.Inc()
ses.Debugf(rm.getCtx(), "resource of the connection %d:%s has been cleaned", rs.ID(), rs.RemoteAddress())
}()
rt := rm.deleteRoutine(rs)

if rt != nil {
ses := rt.getSession()
if ses != nil {
rt.decreaseCount(func() {
account := ses.GetTenantInfo()
accountName := sysAccountName
if account != nil {
accountName = account.GetTenant()
}
metric.ConnectionCounter(accountName).Dec()
rm.accountRoutine.deleteRoutine(int64(account.GetTenantID()), rt)
})
rm.sessionManager.RemoveSession(ses)
ses.Debugf(rm.getCtx(), "the io session was closed.")
}
rt.cleanup()
ses := rt.getSession()
if ses != nil {
ses.Debugf(rm.getCtx(), "clean resource of the connection %d:%s", rs.ID(), rs.RemoteAddress())
defer func() {
ses.Debugf(rm.getCtx(), "resource of the connection %d:%s has been cleaned", rs.ID(), rs.RemoteAddress())
}()
rt.decreaseCount(func() {
account := ses.GetTenantInfo()
accountName := sysAccountName
if account != nil {
accountName = account.GetTenant()
}
metric.ConnectionCounter(accountName).Dec()
rm.accountRoutine.deleteRoutine(int64(account.GetTenantID()), rt)
})
rm.sessionManager.RemoveSession(ses)
ses.Debugf(rm.getCtx(), "the io session was closed.")
}
rt.cleanup()
}

/*
Expand Down

0 comments on commit f27a435

Please sign in to comment.