Skip to content

Commit

Permalink
allow concurrent calls to Close and SetTTL in the ObservedAddrManager
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Sep 7, 2021
1 parent 2cf1c45 commit db0bc33
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion p2p/protocol/identify/obsaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,14 @@ func (oas *ObservedAddrManager) emitSpecificNATType(addrs []*observedAddr, proto
func (oas *ObservedAddrManager) Close() error {
oas.closeOnce.Do(func() {
oas.ctxCancel()

oas.mu.Lock()
oas.refreshTimer.Stop()
oas.refreshTimer = nil
oas.mu.Unlock()

oas.refCount.Wait()
oas.reachabilitySub.Close()
oas.refreshTimer.Stop()
oas.host.Network().StopNotify((*obsAddrNotifiee)(oas))
})
return nil
Expand All @@ -558,6 +563,9 @@ func observerGroup(m ma.Multiaddr) string {
func (oas *ObservedAddrManager) SetTTL(ttl time.Duration) {
oas.mu.Lock()
defer oas.mu.Unlock()
if oas.refreshTimer == nil { // set to nil when we're closing
return
}
oas.ttl = ttl
// refresh every ttl/2 so we don't forget observations from connected peers
oas.refreshTimer.Reset(ttl / 2)
Expand Down

0 comments on commit db0bc33

Please sign in to comment.