Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Troubleshooting too many local IP allocation failure logs #2996

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func NewHost(n network.Network, opts *HostOpts) (*BasicHost, error) {
disableSignedPeerRecord: opts.DisableSignedPeerRecord,
}

h.updateLocalIpAddr()
h.updateLocalIpAddr(false, false)

if h.emitters.evtLocalProtocolsUpdated, err = h.eventbus.Emitter(&event.EvtLocalProtocolsUpdated{}, eventbus.Stateful); err != nil {
return nil, err
Expand Down Expand Up @@ -355,7 +355,7 @@ func NewHost(n network.Network, opts *HostOpts) (*BasicHost, error) {
return h, nil
}

func (h *BasicHost) updateLocalIpAddr() {
func (h *BasicHost) updateLocalIpAddr(v4, v6 bool) (bool, bool) {
h.addrMu.Lock()
defer h.addrMu.Unlock()

Expand All @@ -368,21 +368,31 @@ func (h *BasicHost) updateLocalIpAddr() {
log.Debugw("failed to build Router for kernel's routing table", "error", err)
} else {
if _, _, localIPv4, err := r.Route(net.IPv4zero); err != nil {
log.Debugw("failed to fetch local IPv4 address", "error", err)
if !v4 {
log.Debugw("failed to fetch local IPv4 address", "error", err)
v4 = true
}
} else if localIPv4.IsGlobalUnicast() {
maddr, err := manet.FromIP(localIPv4)
if err == nil {
h.filteredInterfaceAddrs = append(h.filteredInterfaceAddrs, maddr)
}

v4 = false
}

if _, _, localIPv6, err := r.Route(net.IPv6unspecified); err != nil {
log.Debugw("failed to fetch local IPv6 address", "error", err)
if !v6 {
log.Debugw("failed to fetch local IPv6 address", "error", err)
v6 = true
}
} else if localIPv6.IsGlobalUnicast() {
maddr, err := manet.FromIP(localIPv6)
if err == nil {
h.filteredInterfaceAddrs = append(h.filteredInterfaceAddrs, maddr)
}

v6 = false
}
}

Expand All @@ -397,7 +407,7 @@ func (h *BasicHost) updateLocalIpAddr() {
// Then bail. There's nothing else we can do here.
h.filteredInterfaceAddrs = append(h.filteredInterfaceAddrs, manet.IP4Loopback, manet.IP6Loopback)
h.allInterfaceAddrs = h.filteredInterfaceAddrs
return
return v4, v6
}

for _, addr := range ifaceAddrs {
Expand All @@ -421,6 +431,8 @@ func (h *BasicHost) updateLocalIpAddr() {
}
}
}

return v4, v6
}

// Start starts background tasks in the host
Expand Down Expand Up @@ -598,10 +610,13 @@ func (h *BasicHost) background() {
ticker := time.NewTicker(addrChangeTickrInterval)
defer ticker.Stop()

// Check that the address was failed to retrieve at the previous time.
v4, v6 := false , false

for {
// Update our local IP addresses before checking our current addresses.
if len(h.network.ListenAddresses()) > 0 {
h.updateLocalIpAddr()
v4, v6 = h.updateLocalIpAddr(v4, v6)
}
curr := h.Addrs()
emitAddrChange(curr, lastAddrs)
Expand Down