From 11e68092691a9611b7dc54797635c4a797735bf4 Mon Sep 17 00:00:00 2001 From: huangxuesen Date: Mon, 20 Apr 2020 17:29:43 +0800 Subject: [PATCH] ipam: Fix the "close of closed channel" panic When enable ipv4&ipv6 with crd ipam option, cilium panic after restoring old endpoint because of "close of closed channel" Use once.Do to make sure the close action only happen once. Signed-off-by: yangxingwu Signed-off-by: huangxuesen --- pkg/ipam/crd.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/ipam/crd.go b/pkg/ipam/crd.go index fc5a182ab5a1..8785374b1beb 100644 --- a/pkg/ipam/crd.go +++ b/pkg/ipam/crd.go @@ -77,7 +77,8 @@ type nodeStore struct { allocationPoolSize map[Family]int // signal for completion of restoration - restoreFinished chan bool + restoreFinished chan bool + restoreCloseOnce sync.Once conf Configuration } @@ -623,5 +624,7 @@ func (a *crdAllocator) Dump() (map[string]string, string) { // RestoreFinished marks the status of restoration as done func (a *crdAllocator) RestoreFinished() { - close(a.store.restoreFinished) + a.store.restoreCloseOnce.Do(func() { + close(a.store.restoreFinished) + }) }