diff --git a/p2p/simulations/network_test.go b/p2p/simulations/network_test.go index 4ed1e4e6c3..dad67d21ad 100644 --- a/p2p/simulations/network_test.go +++ b/p2p/simulations/network_test.go @@ -76,7 +76,11 @@ func TestSnapshot(t *testing.T) { // subscribe to peer events evC := make(chan *Event) sub := network.Events().Subscribe(evC) - defer sub.Unsubscribe() + defer func() { + if !sub.Closed() { + sub.Unsubscribe() + } + }() // connect nodes in a ring // spawn separate thread to avoid deadlock in the event listeners