Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon: Fix the "close of closed channel" panic #11056

Merged
merged 1 commit into from Apr 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/ipam/crd.go
Expand Up @@ -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
}
Expand Down Expand Up @@ -623,5 +624,7 @@ func (a *crdAllocator) Dump() (map[string]string, string) {

// RestoreFinished marks the status of restoration as done
func (a *crdAllocator) RestoreFinished() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The aim here is to restore all endpoints before triggering sync with upstream, so I think we should close a.store.restoreFinished only after the restoration of both IPv6Allocator and IPv4Allocator are finished. They are called from here:

cilium/daemon/cmd/daemon.go

Lines 491 to 498 in 90b256e

if option.Config.IPAM == option.IPAMCRD || option.Config.IPAM == option.IPAMENI || option.Config.IPAM == option.IPAMAzure {
if option.Config.EnableIPv6 {
d.ipam.IPv6Allocator.RestoreFinished()
}
if option.Config.EnableIPv4 {
d.ipam.IPv4Allocator.RestoreFinished()
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaffcheng @Sen666666 Looking at the code, this comment seems to be a potential further fix that should go in at some point, but does not directly interact with this specific PR #11056 that just fixes a specific crash issue. I'd like to merge this PR as-is to fix the crash, then you can follow up to address these comments. Does that sound reasonable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's address this comment in a follow-up PR.

close(a.store.restoreFinished)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a Once.Do here, it will guarantee that this call is only executed once. (The Once will be a field of nodeStore.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the suggestion, I will try to do some modification.

a.store.restoreCloseOnce.Do(func() {
close(a.store.restoreFinished)
})
}