swarm/network/simulation: adjust disconnections on simulation close

This commit is contained in:
Janos Guljas 2018-08-03 17:52:03 +02:00
parent 6959c93e3e
commit 5d419c3edb

View file

@ -161,6 +161,14 @@ var maxParallelCleanups = 10
// simulation.
func (s *Simulation) Close() {
close(s.done)
// Close all connections before calling the Network Shutdown.
// It is possible that p2p.Server.Stop will block if there are
// existing connections.
for _, c := range s.Net.Conns {
if c.Up {
s.Net.Disconnect(c.One, c.Other)
}
}
sem := make(chan struct{}, maxParallelCleanups)
s.mu.RLock()
cleanupFuncs := make([]func(), len(s.cleanupFuncs))
@ -190,14 +198,6 @@ func (s *Simulation) Close() {
close(s.runC)
}
s.shutdownWG.Wait()
// Close all connections before calling the Network Shutdown.
// It is possible that p2p.Server.Stop will block if there are
// existing connections.
for _, c := range s.Net.Conns {
if c.Up {
s.Net.Disconnect(c.One, c.Other)
}
}
s.Net.Shutdown()
}