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

Commit

Permalink
Merge pull request #1253 from lowzj/fix-issue1198
Browse files Browse the repository at this point in the history
bugfix: check err returned by peerMgr.Get to prevent nil pointer refe…
  • Loading branch information
allencloud authored Mar 19, 2020
2 parents e399394 + d38af90 commit f27e2e4
Showing 1 changed file with 8 additions and 3 deletions.
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

0 comments on commit f27e2e4

Please sign in to comment.