cloudproxy: agent: ssh: wait ssh conn state while passing it out

This commit is contained in:
Yousong Zhou
2021-05-10 13:43:07 +08:00
parent 0319f28da6
commit 1457b37c7d
+8 -7
View File
@@ -178,7 +178,7 @@ func (c *Client) Start(ctx context.Context) {
}
}
func (c *Client) runClientState(ctx context.Context, sshClientC chan *ssh.Client) {
func (c *Client) runClientState(ctx context.Context, sshClientC chan<- *ssh.Client) {
for {
select {
case <-ctx.Done():
@@ -203,12 +203,6 @@ func (c *Client) runClientState(ctx context.Context, sshClientC chan *ssh.Client
func() {
defer sshc.Conn.Close()
select {
case sshClientC <- sshc:
case <-ctx.Done():
return
}
closeC := make(chan struct{})
go func() {
defer close(closeC)
@@ -219,6 +213,13 @@ func (c *Client) runClientState(ctx context.Context, sshClientC chan *ssh.Client
}
}()
select {
case sshClientC <- sshc:
case <-closeC:
case <-ctx.Done():
return
}
select {
case <-closeC:
case <-ctx.Done():