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

cloud-api-adaptor: SecureComms fix panic for closing chan twice #2014

Merged

Conversation

davidhadas
Copy link
Member

Fixes: #2012
Avoid closing an already closed chan.

@bpradipt bpradipt requested a review from yoheiueda August 20, 2024 06:24
Copy link
Member

@bpradipt bpradipt left a comment

Choose a reason for hiding this comment

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

/lgtm

Comment on lines 302 to 310
peer.mutex.Lock()
defer peer.mutex.Unlock()

if peer.terminated == "" {
logger.Printf("%s phase: peer done by >>> %s <<<", peer.phase, who)
peer.terminated = who
if peer.terminated == "" {
peer.terminated = "(unspecified)"
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we use sync.Once here to simplify the logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

The function may run multiple times (for different peer objects). So it seems based on what I read that sync.Once does not fit here.

Copy link
Member

@yoheiueda yoheiueda Aug 20, 2024

Choose a reason for hiding this comment

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

I think you can add a sync.Once object into the SshPeer struct instead of sync.Mutex, then we can call Close() multiple times for different peer objects.

func (peer *SshPeer) Close(who string) {
    peer.once.Do(func() {
        logger.Printf("%s phase: peer done by >>> %s <<<", peer.phase, who)
        peer.sshConn.Close()
        close(peer.done)
   })
}

I think we can also eliminate the terminated field from the struct.

Fixes: confidential-containers#2012
Avoid closing an already closed chan.

Signed-off-by: David Hadas <david.hadas@gmail.com>
Copy link
Member

@yoheiueda yoheiueda left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you very much!

@bpradipt bpradipt merged commit 76e5678 into confidential-containers:main Aug 22, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TestCloudServiceWithSecureComms is flaky
3 participants