swarm/network/stream: add missing WaitGroup.Add and fix errc send blocking

This commit is contained in:
Janos Guljas 2018-04-12 11:12:05 +02:00
parent 2605f59bc0
commit b3be75c537

View file

@ -300,6 +300,7 @@ func runSyncTest(chunkCount int, nodeCount int, live bool, history bool) error {
if wsDoneC == nil { if wsDoneC == nil {
continue continue
} }
rpcSubscriptionsWg.Add(1)
go func() { go func() {
<-wsDoneC <-wsDoneC
rpcSubscriptionsWg.Done() rpcSubscriptionsWg.Done()
@ -628,7 +629,10 @@ func watchSubscriptionEvents(ctx context.Context, id discover.NodeID, client *rp
case <-quitC: case <-quitC:
return return
case <-ctx.Done(): case <-ctx.Done():
errc <- ctx.Err() select {
case errc <- ctx.Err():
case <-quitC:
}
return return
case e := <-events: case e := <-events:
//just catch SubscribeMsg //just catch SubscribeMsg
@ -637,7 +641,10 @@ func watchSubscriptionEvents(ctx context.Context, id discover.NodeID, client *rp
} }
case err := <-sub.Err(): case err := <-sub.Err():
if err != nil { 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 return
} }
} }