Skip to content

Commit

Permalink
executor: fix panic when fetching processlist table data in some ca…
Browse files Browse the repository at this point in the history
…ses (#11688) (#16309)
  • Loading branch information
qw4990 authored Apr 13, 2020
1 parent 114ad7e commit b7f34bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ func (cc *clientConn) connectInfo() *variable.ConnectionInfo {
// ShowProcessList implements the SessionManager interface.
func (s *Server) ShowProcessList() map[uint64]*util.ProcessInfo {
s.rwlock.RLock()
defer s.rwlock.RUnlock()
rs := make(map[uint64]*util.ProcessInfo, len(s.clients))
for _, client := range s.clients {
if atomic.LoadInt32(&client.status) == connStatusWaitShutdown {
Expand All @@ -457,7 +458,6 @@ func (s *Server) ShowProcessList() map[uint64]*util.ProcessInfo {
rs[pi.ID] = pi
}
}
s.rwlock.RUnlock()
return rs
}

Expand Down
6 changes: 5 additions & 1 deletion util/processinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ func (pi *ProcessInfo) txnStartTs(tz *time.Location) (txnStart string) {
// ToRow returns []interface{} for the row data of
// "SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST".
func (pi *ProcessInfo) ToRow(tz *time.Location) []interface{} {
return append(pi.ToRowForShow(true), pi.StmtCtx.MemTracker.BytesConsumed(), pi.txnStartTs(tz))
bytesConsumed := int64(0)
if pi.StmtCtx.MemTracker != nil {
bytesConsumed = pi.StmtCtx.MemTracker.BytesConsumed()
}
return append(pi.ToRowForShow(true), bytesConsumed, pi.txnStartTs(tz))
}

// SessionManager is an interface for session manage. Show processlist and
Expand Down

0 comments on commit b7f34bf

Please sign in to comment.