From a615c186643cdd9bc9566deb325eaa57e32de3de Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 2 Mar 2019 10:18:21 +0200 Subject: [PATCH 1/2] mutex protect Status to pacify the race detector --- p2p/host/autonat/autonat.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/p2p/host/autonat/autonat.go b/p2p/host/autonat/autonat.go index e0418c45f8..410d733edd 100644 --- a/p2p/host/autonat/autonat.go +++ b/p2p/host/autonat/autonat.go @@ -85,6 +85,8 @@ func NewAutoNAT(ctx context.Context, h host.Host, getAddrs GetAddrs) AutoNAT { } func (as *AmbientAutoNAT) Status() NATStatus { + as.mx.Lock() + defer as.mx.Unlock() return as.status } From 5ab68af1bcb044afbd836cd37e13f237c3d84d2c Mon Sep 17 00:00:00 2001 From: vyzo Date: Sat, 2 Mar 2019 10:18:37 +0200 Subject: [PATCH 2/2] lock peer table in test to pacify the race detector --- p2p/host/autonat/autonat_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/p2p/host/autonat/autonat_test.go b/p2p/host/autonat/autonat_test.go index 5436619846..9e81453675 100644 --- a/p2p/host/autonat/autonat_test.go +++ b/p2p/host/autonat/autonat_test.go @@ -73,8 +73,9 @@ func newDialResponseError(status pb.Message_ResponseStatus, text string) *pb.Mes func makeAutoNAT(ctx context.Context, t *testing.T, ash host.Host) (host.Host, AutoNAT) { h := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx)) a := NewAutoNAT(ctx, h, nil) + a.(*AmbientAutoNAT).mx.Lock() a.(*AmbientAutoNAT).peers[ash.ID()] = ash.Addrs() - + a.(*AmbientAutoNAT).mx.Unlock() return h, a }