Skip to content

Commit

Permalink
dhcp: remove leases when they are released
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dcbw committed Feb 8, 2018
1 parent 61c3c42 commit 596480e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/ipam/dhcp/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 596480e

Please sign in to comment.