fix autonat race

fix #7947
move `BasicHost.AutoNat` to a private field (it has no public method and shouldn't be accessed afaik.
Instead add a setter for config that sets it while holding the address mutex to prevent reads of the
field at the same time.
This commit is contained in:
Will Scott
2021-02-26 23:21:36 -08:00
parent bbde01b33e
commit c2c5918483
3 changed files with 17 additions and 5 deletions

View File

@@ -203,7 +203,7 @@ func TestHostAddrsFactory(t *testing.T) {
}
var err error
h.AutoNat, err = autonat.New(ctx, h, autonat.WithReachability(network.ReachabilityPublic))
h.autoNat, err = autonat.New(ctx, h, autonat.WithReachability(network.ReachabilityPublic))
if err != nil {
t.Fatalf("should be able to attach autonat: %v", err)
}