Skip to content

Commit dbcee58

Browse files
authored
fix(p2p/peerTracker): fix bootstraping (#169)
1 parent 3b63466 commit dbcee58

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

p2p/peer_tracker.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,14 @@ func (p *peerTracker) bootstrap(ctx context.Context, trusted []libpeer.ID) error
8282
connectCtx, cancel := context.WithTimeout(context.Background(), time.Second*60)
8383
defer cancel()
8484

85+
wg := sync.WaitGroup{}
86+
wg.Add(len(trusted))
8587
for _, trust := range trusted {
86-
go p.connectToPeer(connectCtx, trust)
88+
trust := trust
89+
go func() {
90+
defer wg.Done()
91+
p.connectToPeer(connectCtx, trust)
92+
}()
8793
}
8894

8995
// short-circuit if pidstore was not provided
@@ -96,9 +102,15 @@ func (p *peerTracker) bootstrap(ctx context.Context, trusted []libpeer.ID) error
96102
return err
97103
}
98104

105+
wg.Add(len(prevSeen))
99106
for _, peer := range prevSeen {
100-
go p.connectToPeer(connectCtx, peer)
107+
peer := peer
108+
go func() {
109+
defer wg.Done()
110+
p.connectToPeer(connectCtx, peer)
111+
}()
101112
}
113+
wg.Wait()
102114
return nil
103115
}
104116

0 commit comments

Comments
 (0)