Skip to content

Commit b62e97f

Browse files
authored
fix(p2p): fix race condition caused by startTestNetwork (#801)
The `require.NotEmpty` utility reads through the struct fields of the Host via reflection, while the internal background routine in the host also accesses its field, causing race conditions. The fix is to use `require.NotNil` as it only checks whether the Host is nil or not without accessing its internal fields
1 parent 8640e67 commit b62e97f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

p2p/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func startTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]hos
8080
require.NoError(err)
8181
host, err := mnet.AddPeer(privKey, addr)
8282
require.NoError(err)
83-
require.NotEmpty(host)
83+
require.NotNil(host)
8484
} else {
8585
_, err := mnet.GenPeer()
8686
require.NoError(err)

0 commit comments

Comments
 (0)