Skip to content

Commit

Permalink
Fix goroutine leak in ipaddress
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <[email protected]>
  • Loading branch information
Vladimir Popov committed Sep 29, 2021
1 parent 8237d19 commit 320bcb1
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,18 @@ func create(ctx context.Context, conn *networkservice.Connection, isClient bool)

ch := make(chan netlink.AddrUpdate)
done := make(chan struct{})
defer close(done)

if err := netlink.AddrSubscribeAt(targetNetNS, ch, done); err != nil {
return errors.Wrapf(err, "failed to subscribe for interface address updates")
}

defer func() {
close(done)
// `ch` should be fully read after the `done` close to prevent goroutine leak in `netlink.AddrSubscribeAt`
for range ch {
}
}()

for _, ipNet := range ipNets {
now := time.Now()
addr := &netlink.Addr{
Expand Down

0 comments on commit 320bcb1

Please sign in to comment.