From 02b9c5724dc08fdf4b3d11e6c27863dc52632e61 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 29 Aug 2017 19:11:58 -0700 Subject: [PATCH 1/2] 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 From e7faa78d7c3ba2b0379b9e1bca52f12f3fe22ea9 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 29 Aug 2017 19:42:33 -0700 Subject: [PATCH 2/2] log when dropping messages --- floodsub.go | 1 + 1 file changed, 1 insertion(+) diff --git a/floodsub.go b/floodsub.go index c252148..b21caad 100644 --- a/floodsub.go +++ b/floodsub.go @@ -346,6 +346,7 @@ func (p *PubSub) publishMessage(from peer.ID, msg *pb.Message) error { select { case mch <- out: default: + log.Infof("dropping message to peer %s: queue full", pid) // Drop it. The peer is too slow. } }