-
Notifications
You must be signed in to change notification settings - Fork 95
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
cloud-api-adaptor: SecureComms fix panic for closing chan twice #2014
Conversation
a6edaf5
to
ccc518d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
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)" | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
ccc518d
to
6cbc206
Compare
There was a problem hiding this 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!
Fixes: #2012
Avoid closing an already closed chan.