From b3be75c537dbb9aa1729ee08abb9768c462c966c Mon Sep 17 00:00:00 2001 From: Janos Guljas Date: Thu, 12 Apr 2018 11:12:05 +0200 Subject: [PATCH] swarm/network/stream: add missing WaitGroup.Add and fix errc send blocking --- swarm/network/stream/snapshot_sync_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/swarm/network/stream/snapshot_sync_test.go b/swarm/network/stream/snapshot_sync_test.go index 20dc13799c..a498013e3c 100644 --- a/swarm/network/stream/snapshot_sync_test.go +++ b/swarm/network/stream/snapshot_sync_test.go @@ -300,6 +300,7 @@ func runSyncTest(chunkCount int, nodeCount int, live bool, history bool) error { if wsDoneC == nil { continue } + rpcSubscriptionsWg.Add(1) go func() { <-wsDoneC rpcSubscriptionsWg.Done() @@ -628,7 +629,10 @@ func watchSubscriptionEvents(ctx context.Context, id discover.NodeID, client *rp case <-quitC: return case <-ctx.Done(): - errc <- ctx.Err() + select { + case errc <- ctx.Err(): + case <-quitC: + } return case e := <-events: //just catch SubscribeMsg @@ -637,7 +641,10 @@ func watchSubscriptionEvents(ctx context.Context, id discover.NodeID, client *rp } case err := <-sub.Err(): if err != nil { - errc <- fmt.Errorf("error getting peer events for node %v: %v", id, err) + select { + case errc <- fmt.Errorf("error getting peer events for node %v: %v", id, err): + case <-quitC: + } return } }