From a93b44b226284159bfefc744040e15e672598674 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 15 Jul 2017 20:18:17 -0700 Subject: [PATCH] Only open a message sender when we have messages to send License: MIT Signed-off-by: Jeromy --- exchange/bitswap/wantmanager.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/exchange/bitswap/wantmanager.go b/exchange/bitswap/wantmanager.go index 780282a740f..4ae12f4998a 100644 --- a/exchange/bitswap/wantmanager.go +++ b/exchange/bitswap/wantmanager.go @@ -187,15 +187,6 @@ func (mq *msgQueue) runQueue(ctx context.Context) { } func (mq *msgQueue) doWork(ctx context.Context) { - if mq.sender == nil { - err := mq.openSender(ctx) - if err != nil { - log.Infof("cant open message sender to peer %s: %s", mq.p, err) - // TODO: cant connect, what now? - return - } - } - // grab outgoing message mq.outlk.Lock() wlm := mq.out @@ -206,6 +197,16 @@ func (mq *msgQueue) doWork(ctx context.Context) { mq.out = nil mq.outlk.Unlock() + // NB: only open a stream if we actually have data to send + if mq.sender == nil { + err := mq.openSender(ctx) + if err != nil { + log.Infof("cant open message sender to peer %s: %s", mq.p, err) + // TODO: cant connect, what now? + return + } + } + // send wantlist updates for { // try to send this message until we fail. err := mq.sender.SendMsg(ctx, wlm)