diff --git a/p2p/host/relaysvc/relay_test.go b/p2p/host/relaysvc/relay_test.go index 4117e11966..83a1784ea2 100644 --- a/p2p/host/relaysvc/relay_test.go +++ b/p2p/host/relaysvc/relay_test.go @@ -55,13 +55,13 @@ func TestReachabilityChangeEvent(t *testing.T) { require.Eventually( t, func() bool { rmgr.mutex.Lock(); defer rmgr.mutex.Unlock(); relay = rmgr.relay; return relay != nil }, - 1*time.Second, + 3*time.Second, 100*time.Millisecond, "relay should be set on public event") emitter.Emit(evt) require.Never(t, func() bool { rmgr.mutex.Lock(); defer rmgr.mutex.Unlock(); return relay != rmgr.relay }, - 1*time.Second, + 3*time.Second, 100*time.Millisecond, "relay should not be updated on receiving the same event") } diff --git a/p2p/protocol/circuitv2/relay/relay.go b/p2p/protocol/circuitv2/relay/relay.go index 81857827bf..e3c8f47580 100644 --- a/p2p/protocol/circuitv2/relay/relay.go +++ b/p2p/protocol/circuitv2/relay/relay.go @@ -52,7 +52,6 @@ type Relay struct { constraints *constraints scope network.ResourceScopeSpan notifiee network.Notifiee - wg sync.WaitGroup mx sync.Mutex rsvp map[peer.ID]time.Time @@ -106,7 +105,6 @@ func New(h host.Host, opts ...Option) (*Relay, error) { if r.metricsTracer != nil { r.metricsTracer.RelayStatus(true) } - r.wg.Add(1) go r.background() return r, nil @@ -122,10 +120,10 @@ func (r *Relay) Close() error { r.host.Network().StopNotify(r.notifiee) r.scope.Done() r.cancel() + r.gc() if r.metricsTracer != nil { r.metricsTracer.RelayStatus(false) } - r.wg.Wait() return nil } r.mx.Unlock() @@ -636,8 +634,6 @@ func (r *Relay) background() { case <-ticker.C: r.gc() case <-r.ctx.Done(): - r.gc() - r.wg.Done() return } }