dhcp: don't try to close the lease stop channel multiple times

Fixes: https://github.com/containernetworking/plugins/issues/105
This commit is contained in:
Dan Williams
2018-02-07 11:41:23 -06:00
parent b522ed6aae
commit 61c3c42107
2 changed files with 70 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import (
"math/rand"
"net"
"sync"
"sync/atomic"
"time"
"github.com/d2g/dhcp4"
@ -55,6 +56,7 @@ type DHCPLease struct {
renewalTime time.Time
rebindingTime time.Time
expireTime time.Time
stopping uint32
stop chan struct{}
wg sync.WaitGroup
}
@ -106,7 +108,9 @@ func AcquireLease(clientID, netns, ifName string) (*DHCPLease, error) {
// Stop terminates the background task that maintains the lease
// and issues a DHCP Release
func (l *DHCPLease) Stop() {
close(l.stop)
if atomic.CompareAndSwapUint32(&l.stopping, 0, 1) {
close(l.stop)
}
l.wg.Wait()
}