Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

bugfix: check err returned by peerMgr.Get to prevent nil pointer refe… #1253

Merged
merged 1 commit into from
Mar 19, 2020
Merged
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
11 changes: 8 additions & 3 deletions supernode/daemon/mgr/task/manager_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,21 @@ func (tm *Manager) parseAvailablePeers(ctx context.Context, clientID string, tas
return true, finishInfo, nil
}

// Get peerName to represent peer in metrics.
peer, _ := tm.peerMgr.Get(context.Background(), dfgetTask.PeerID)
// get scheduler pieceResult
logrus.Debugf("start scheduler for taskID: %s clientID: %s", task.ID, clientID)
startTime := time.Now()
pieceResult, err := tm.schedulerMgr.Schedule(ctx, task.ID, clientID, dfgetTask.PeerID)
if err != nil {
return false, nil, err
}
tm.metrics.scheduleDurationMilliSeconds.WithLabelValues(peer.IP.String()).Observe(timeutils.SinceInMilliseconds(startTime))
timeCost := timeutils.SinceInMilliseconds(startTime)
// Get peerName to represent peer in metrics.
if peer, err := tm.peerMgr.Get(context.Background(), dfgetTask.PeerID); err == nil {
tm.metrics.scheduleDurationMilliSeconds.WithLabelValues(peer.IP.String()).Observe(timeCost)
} else {
logrus.Warnf("failed to get peer with peerId(%s) taskId(%s): %v",
dfgetTask.PeerID, task.ID, err)
}
logrus.Debugf("get scheduler result length(%d) with taskID(%s) and clientID(%s)", len(pieceResult), task.ID, clientID)

if len(pieceResult) == 0 {
Expand Down