From aead4ab555e0c3469002dba54e9e3a7bc69d9e79 Mon Sep 17 00:00:00 2001 From: Erik Grinaker Date: Wed, 27 Jan 2021 22:05:48 +0100 Subject: [PATCH] test: fix test data race in p2p.MemoryTransport with logger (#5995) This patches over a test data race where the logger would try to read struct internals via `reflect` while these were concurrently modified (specifically `MemoryTransport.closeOnce`). --- p2p/transport_memory.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/p2p/transport_memory.go b/p2p/transport_memory.go index b47ff6919..96a948ce1 100644 --- a/p2p/transport_memory.go +++ b/p2p/transport_memory.go @@ -135,6 +135,16 @@ func newMemoryTransport( } } +// String displays the transport. +// +// FIXME: The Transport interface should either have Name() or embed +// fmt.Stringer. This is necessary since we log the transport (to know which one +// it is), and if it doesn't implement fmt.Stringer then it inspects all struct +// contents via reflect, which triggers the race detector. +func (t *MemoryTransport) String() string { + return "memory" +} + // Accept implements Transport. func (t *MemoryTransport) Accept(ctx context.Context) (Connection, error) { select {