From d57c3fa4b1360bb560251d6d45449f728e5e6ecb Mon Sep 17 00:00:00 2001 From: Wondertan Date: Thu, 23 Mar 2023 12:12:43 +0100 Subject: [PATCH] fix(p2p): fix race condition cause by startTestNetwork The require.NotEmpty utility reads throught struct field of the Host, while internal background routine in the host access this field as well, causing a race condition. The fix is to use require.NotNil is it only check whether the Host is nil or not without accessing it's internal fields --- p2p/utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/p2p/utils_test.go b/p2p/utils_test.go index f45a008529..027901b4f7 100644 --- a/p2p/utils_test.go +++ b/p2p/utils_test.go @@ -80,7 +80,7 @@ func startTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]hos require.NoError(err) host, err := mnet.AddPeer(privKey, addr) require.NoError(err) - require.NotEmpty(host) + require.NotNil(host) } else { _, err := mnet.GenPeer() require.NoError(err)