Skip to content

Commit

Permalink
Merge pull request #2136 from dhilgarth/feature/fix-shutdown-panic
Browse files Browse the repository at this point in the history
Don't panic upon shutdown when running in standalone mode
  • Loading branch information
thomasferrandiz authored Dec 18, 2024
2 parents e810d96 + d4bf2b9 commit 69ce8cb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,26 @@ func WatchLeases(ctx context.Context, sm Manager, ownLease *lease.Lease, receive
// and it needs to diff the latest snapshot with its saved state and generate events
func WatchLease(ctx context.Context, sm Manager, sn ip.IP4Net, sn6 ip.IP6Net, receiver chan lease.Event) {
leaseWatchChan := make(chan []lease.LeaseWatchResult)
var closeOnce sync.Once

// Helper function to close the receiver channel safely
closeReceiver := func() {
closeOnce.Do(func() {
close(receiver)
})
}

go func() {
err := sm.WatchLease(ctx, sn, sn6, leaseWatchChan)
if err != nil {
if err == context.Canceled || err == context.DeadlineExceeded {
log.Infof("%v, close receiver chan", err)
close(receiver)
closeReceiver()
return
}

log.Errorf("Subnet watch failed: %v", err)
close(receiver)
closeReceiver()
return
}

Expand All @@ -199,5 +207,5 @@ func WatchLease(ctx context.Context, sm Manager, sn ip.IP4Net, sn6 ip.IP6Net, re

}
log.Info("leaseWatchChan channel closed")
close(receiver)
closeReceiver()
}

0 comments on commit 69ce8cb

Please sign in to comment.