Skip to content

Commit

Permalink
DHCP lease maintenance should terminate when interface no longer exists.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dougbtv committed Jan 21, 2025
1 parent e4ca66b commit 3cb9c6b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions plugins/ipam/dhcp/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 3cb9c6b

Please sign in to comment.