Skip to content

Commit

Permalink
pillar/devicenetwork: fix goroutine leak
Browse files Browse the repository at this point in the history
introduced in 8573372

without this fix, the goroutine is blocked by trying to send
into a channel that has no receiver

Signed-off-by: Christoph Ostarek <[email protected]>
  • Loading branch information
christoph-zededa committed Nov 4, 2024
1 parent 7534022 commit 5894edb
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pkg/pillar/devicenetwork/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,13 @@ func ResolveWithPortsLambda(domain string,
copy(srcIPCopy, srcIP)
countDNSRequests++
go func(dnsIP, srcIP net.IP) {
select {
case work <- struct{}{}:
// if writable, means less than dnsMaxParallelRequests goroutines are currently running
}
defer func() {
wg.Done()
<-work
}()
// if writable, means less than dnsMaxParallelRequests goroutines are currently running
work <- struct{}{}

select {
case <-quit:
// will return in case the quit chan has been closed,
Expand All @@ -150,21 +153,24 @@ func ResolveWithPortsLambda(domain string,
errs = append(errs, err)
}
if response != nil {
resolvedIPsChan <- response
select {
case <-quit:
case resolvedIPsChan <- response:
}
}
<-work
wg.Done()
}(dnsIPCopy, srcIPCopy)
}
}
}

wgChan := make(chan struct{})

go func() {
wg.Wait()
close(wgChan)
}()

defer close(quit)
select {
case <-wgChan:
var responses []DNSResponse
Expand All @@ -183,7 +189,7 @@ func ResolveWithPortsLambda(domain string,
}
return responses, errs
case ip := <-resolvedIPsChan:
close(quit)
return ip, nil
}

}

0 comments on commit 5894edb

Please sign in to comment.