drop messages to slow peers
Instead of spawning a go routine for every message sent to every peer, buffer them (actually, we already buffer 32 so this didn't need to be changed) and drop messages when the buffer fills up. fixes https://github.com/ipfs/go-ipfs/issues/4066 (writing to a channel in a go routine can be dangerous...)
This commit is contained in:
parent
b93dd9968a
commit
02b9c5724d
|
@ -343,7 +343,11 @@ func (p *PubSub) publishMessage(from peer.ID, msg *pb.Message) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() { mch <- out }()
|
select {
|
||||||
|
case mch <- out:
|
||||||
|
default:
|
||||||
|
// Drop it. The peer is too slow.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue