From 3cb9c6b8e724e53b3f66665ad6bc14784306a1d8 Mon Sep 17 00:00:00 2001 From: dougbtv Date: Tue, 21 Jan 2025 11:00:48 -0500 Subject: [PATCH] DHCP lease maintenance should terminate when interface no longer exists. Due to oberservations that threads can grow and the dhcp daemon uses an increasing amount of memory. This situation can happen organically when using say, bridge CNI, and the bridge has been removed outside of the bridge CNI lifecycle, and an interface no longer exists on a pod. Signed-off-by: dougbtv --- plugins/ipam/dhcp/lease.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/ipam/dhcp/lease.go b/plugins/ipam/dhcp/lease.go index ffc379570..dcc7913f5 100644 --- a/plugins/ipam/dhcp/lease.go +++ b/plugins/ipam/dhcp/lease.go @@ -292,6 +292,11 @@ func (l *DHCPLease) maintain() { for { var sleepDur time.Duration + if _, err := netlink.LinkByName(l.link.Attrs().Name); err != nil { + log.Printf("%v: interface %s no longer exists, terminating lease maintenance", l.clientID, l.link.Attrs().Name) + return + } + switch state { case leaseStateBound: sleepDur = time.Until(l.renewalTime) @@ -336,6 +341,7 @@ func (l *DHCPLease) maintain() { log.Printf("%v: Checking lease", l.clientID) case <-l.stop: + log.Printf("%v: received stop signal, releasing lease", l.clientID) if err := l.release(); err != nil { log.Printf("%v: failed to release DHCP lease: %v", l.clientID, err) }