mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
cloudproxy: agent: ssh: wait ssh conn state while passing it out
This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user