From 72f041b7591d28fc28e621c567af291702fe3c36 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Sat, 19 Dec 2020 07:35:16 +0100 Subject: [PATCH] p2p: fix data race in MakeSwitch test helper (#5810) Fixes #5809. --- p2p/test_util.go | 8 ++++---- p2p/transport_mconn.go | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/p2p/test_util.go b/p2p/test_util.go index 1d352eefd..2736d7f74 100644 --- a/p2p/test_util.go +++ b/p2p/test_util.go @@ -169,15 +169,15 @@ func MakeSwitch( logger := log.TestingLogger().With("switch", i) t := NewMConnTransport(logger, nodeInfo, nodeKey.PrivKey, MConnConfig(cfg)) - if err := t.Listen(addr.Endpoint()); err != nil { - panic(err) - } - // TODO: let the config be passed in? sw := initSwitch(i, NewSwitch(cfg, t, opts...)) sw.SetLogger(log.TestingLogger().With("switch", i)) sw.SetNodeKey(nodeKey) + if err := t.Listen(addr.Endpoint()); err != nil { + panic(err) + } + ni := nodeInfo ni.Channels = []byte{} for ch := range sw.reactorsByCh { diff --git a/p2p/transport_mconn.go b/p2p/transport_mconn.go index a55ca4403..7baabb2eb 100644 --- a/p2p/transport_mconn.go +++ b/p2p/transport_mconn.go @@ -129,6 +129,11 @@ func NewMConnTransport( } // SetChannelDescriptors implements Transport. +// +// This is not concurrency-safe, and must be called before listening. +// +// FIXME: This is here for compatibility with existing switch code, +// it should be passed via the constructor instead. func (m *MConnTransport) SetChannelDescriptors(chDescs []*conn.ChannelDescriptor) { m.channelDescs = chDescs }