les: fix channel panic

This commit is contained in:
rjl493456442 2018-09-21 00:02:24 +08:00
parent f55c26ae6d
commit 762185b145

View file

@ -174,18 +174,18 @@ func (sp selectPeerItem) Weight() int64 {
// nextRequest returns the next possible request from any peer, along with the // nextRequest returns the next possible request from any peer, along with the
// associated peer and necessary waiting time // associated peer and necessary waiting time
func (d *requestDistributor) nextRequest() (distPeer, *distReq, time.Duration) { func (d *requestDistributor) nextRequest() (distPeer, *distReq, time.Duration) {
checkedPeers := make(map[distPeer]struct{})
elem := d.reqQueue.Front()
var ( var (
bestPeer distPeer bestPeer distPeer
bestReq *distReq bestReq *distReq
bestWait time.Duration bestWait time.Duration
sel *weightedRandomSelect sel *weightedRandomSelect
checkedPeers = make(map[distPeer]struct{})
) )
d.peerLock.RLock() d.peerLock.RLock()
defer d.peerLock.RUnlock() defer d.peerLock.RUnlock()
elem := d.reqQueue.Front()
for (len(d.peers) > 0 || elem == d.reqQueue.Front()) && elem != nil { for (len(d.peers) > 0 || elem == d.reqQueue.Front()) && elem != nil {
req := elem.Value.(*distReq) req := elem.Value.(*distReq)
canSend := false canSend := false