From 02b9c5724dc08fdf4b3d11e6c27863dc52632e61 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 29 Aug 2017 19:11:58 -0700 Subject: [PATCH] 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...) --- floodsub.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/floodsub.go b/floodsub.go index adefd5f..c252148 100644 --- a/floodsub.go +++ b/floodsub.go @@ -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