diff --git a/pkg/services/services.go b/pkg/services/services.go index 711b57d1..df7bc01c 100644 --- a/pkg/services/services.go +++ b/pkg/services/services.go @@ -227,17 +227,22 @@ func (p *Processor) configureService(ctx context.Context, inst *instance.Instanc if index == -1 { log.Error("unable to find proper VIPConfig for the DHCPv4") } else { - for ip := range inst.DHCPv4Client.IPChannel() { - log.Debug("IP changed", "ip", ip) - inst.VIPConfigs[index].VIP = ip - inst.DHCPInterfaceIPv4 = ip - if !p.config.DisableServiceUpdates { - if err := p.updateStatus(ctx, inst); err != nil { - log.Warn("updating svc", "err", err) + for { + select { + case <-ctx.Done(): + log.Debug("IPv4 update watcher stopping") + return + case ip := <-inst.DHCPv4Client.IPChannel(): + log.Debug("IP changed", "ip", ip) + inst.VIPConfigs[index].VIP = ip + inst.DHCPInterfaceIPv4 = ip + if !p.config.DisableServiceUpdates { + if err := p.updateStatus(ctx, inst); err != nil { + log.Warn("updating svc", "err", err) + } } } } - log.Debug("IPv4 update channel closed, stopping") } }) } @@ -255,17 +260,22 @@ func (p *Processor) configureService(ctx context.Context, inst *instance.Instanc if index == -1 { log.Error("unable to find proper VIPConfig for the DHCPv6") } else { - for ip := range inst.DHCPv6Client.IPChannel() { - log.Debug("IP changed", "ip", ip) - inst.VIPConfigs[index].VIP = ip - inst.DHCPInterfaceIPv6 = ip - if !p.config.DisableServiceUpdates { - if err := p.updateStatus(ctx, inst); err != nil { - log.Warn("updating svc", "err", err) + for { + select { + case <-ctx.Done(): + log.Debug("IPv6 update watcher stopping") + return + case ip := <-inst.DHCPv6Client.IPChannel(): + log.Debug("IP changed", "ip", ip) + inst.VIPConfigs[index].VIP = ip + inst.DHCPInterfaceIPv6 = ip + if !p.config.DisableServiceUpdates { + if err := p.updateStatus(ctx, inst); err != nil { + log.Warn("updating svc", "err", err) + } } } } - log.Debug("IPv6 update channel closed, stopping") } }) } diff --git a/pkg/vip/dhcpv4.go b/pkg/vip/dhcpv4.go index 2f448696..b8eca93d 100644 --- a/pkg/vip/dhcpv4.go +++ b/pkg/vip/dhcpv4.go @@ -73,7 +73,6 @@ func (c *DHCPv4Client) Stop() { func (c *DHCPv4Client) close() { c.stopOnce.Do(func() { - close(c.ipChan) close(c.stopChan) }) } @@ -284,7 +283,12 @@ RequestLoop: } if c.ipChan != nil { - c.ipChan <- lease.ACK.YourIPAddr.String() + // Nothing closes ipChan, so never block on a consumer that already stopped. + select { + case c.ipChan <- lease.ACK.YourIPAddr.String(): + case <-c.stopChan: + case <-ctx.Done(): + } } return lease, nil diff --git a/pkg/vip/dhcpv6.go b/pkg/vip/dhcpv6.go index 788a1079..3a41434c 100644 --- a/pkg/vip/dhcpv6.go +++ b/pkg/vip/dhcpv6.go @@ -307,7 +307,12 @@ RequestLoop: } if c.ipChan != nil { - c.ipChan <- addr.IPv6Addr.String() + // Nothing closes ipChan, so never block on a consumer that already stopped. + select { + case c.ipChan <- addr.IPv6Addr.String(): + case <-c.stopChan: + case <-ctx.Done(): + } } return addr, nil