fix: dhcp panic and leak potential

Signed-off-by: Marcel Fest <marcel.fest@telekom.de>
This commit is contained in:
Marcel Fest
2026-09-15 14:57:51 +02:00
committed by Marcel Fest
parent d6129c8299
commit c925fb7cd9
3 changed files with 38 additions and 19 deletions

View File

@@ -227,7 +227,12 @@ 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() {
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
@@ -237,7 +242,7 @@ func (p *Processor) configureService(ctx context.Context, inst *instance.Instanc
}
}
}
log.Debug("IPv4 update channel closed, stopping")
}
}
})
}
@@ -255,7 +260,12 @@ 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() {
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
@@ -265,7 +275,7 @@ func (p *Processor) configureService(ctx context.Context, inst *instance.Instanc
}
}
}
log.Debug("IPv6 update channel closed, stopping")
}
}
})
}

View File

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

View File

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