From 596480eadc384f8f3eb60ba920bcc62998b34ed6 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 7 Feb 2018 11:42:05 -0600 Subject: [PATCH] dhcp: remove leases when they are released Don't lock around the Stop() operation though, as that may take a while and block other operations. That may mean we call Stop() multiple times, but the Lease object should handle that correctly itself. --- plugins/ipam/dhcp/daemon.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/ipam/dhcp/daemon.go b/plugins/ipam/dhcp/daemon.go index a5316d75..8ab977a3 100644 --- a/plugins/ipam/dhcp/daemon.go +++ b/plugins/ipam/dhcp/daemon.go @@ -93,6 +93,7 @@ func (d *DHCP) Release(args *skel.CmdArgs, reply *struct{}) error { if l := d.getLease(args.ContainerID, conf.Name); l != nil { l.Stop() + d.clearLease(args.ContainerID, conf.Name) } return nil @@ -118,6 +119,14 @@ func (d *DHCP) setLease(contID, netName string, l *DHCPLease) { d.leases[contID+netName] = l } +func (d *DHCP) clearLease(contID, netName string) { + d.mux.Lock() + defer d.mux.Unlock() + + // TODO(eyakubovich): hash it to avoid collisions + delete(d.leases, contID+netName) +} + func getListener() (net.Listener, error) { l, err := activation.Listeners(true) if err != nil {