p2p/discover: fix pending replies iteration

Range expressions capture the length of the slice once before the first
iteration. A range expression cannot be used here since the loop
modifies the slice variable (including length changes).
This commit is contained in:
Felix Lange 2015-02-17 15:14:12 +01:00
parent 643eda5c2d
commit 7ea131d4ff
1 changed files with 2 additions and 1 deletions

View File

@ -253,7 +253,8 @@ func (t *udp) loop() {
case reply := <-t.replies:
// run matching callbacks, remove if they return false.
for i, p := range pending {
for i := 0; i < len(pending); i++ {
p := pending[i]
if reply.from == p.from && reply.ptype == p.ptype && p.callback(reply.data) {
p.errc <- nil
copy(pending[i:], pending[i+1:])