diff --git a/pkg/cloudproxy/agent/ssh/client.go b/pkg/cloudproxy/agent/ssh/client.go index 75e4560ea0..0e337a80f7 100644 --- a/pkg/cloudproxy/agent/ssh/client.go +++ b/pkg/cloudproxy/agent/ssh/client.go @@ -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():