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.
This commit is contained in:
Dan Williams
2018-02-07 11:42:05 -06:00
parent 61c3c42107
commit 596480eadc

View File

@ -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 {