From 8b95e77770e95b2635a8293f81f46bbb4f34b708 Mon Sep 17 00:00:00 2001 From: ucwong Date: Fri, 5 Jan 2024 03:53:25 +0800 Subject: [PATCH] p2p/simulations : avoid duplicate unsubscribe --- p2p/simulations/network_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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