fix context leak when autorelay option errors

This commit is contained in:
Marten Seemann 2022-04-05 15:13:43 +01:00
parent 6bb54b5773
commit ca6ded2a81
1 changed files with 1 additions and 1 deletions

View File

@ -41,13 +41,13 @@ func NewAutoRelay(bhost *basic.BasicHost, opts ...Option) (*AutoRelay, error) {
addrsF: bhost.AddrsFactory,
status: network.ReachabilityUnknown,
}
r.ctx, r.ctxCancel = context.WithCancel(context.Background())
conf := defaultConfig
for _, opt := range opts {
if err := opt(&conf); err != nil {
return nil, err
}
}
r.ctx, r.ctxCancel = context.WithCancel(context.Background())
r.peerChanOut = make(chan peer.AddrInfo, conf.maxCandidates)
r.conf = &conf
r.relayFinder = newRelayFinder(bhost, r.peerChanOut, &conf)