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:
Steven Allen 2017-08-29 19:11:58 -07:00
parent b93dd9968a
commit 02b9c5724d
1 changed files with 5 additions and 1 deletions

View File

@ -343,7 +343,11 @@ func (p *PubSub) publishMessage(from peer.ID, msg *pb.Message) error {
continue
}
go func() { mch <- out }()
select {
case mch <- out:
default:
// Drop it. The peer is too slow.
}
}
return nil