diff --git a/pkg/shell/pty.go b/pkg/shell/pty.go index c9339e79..2e7dafd7 100644 --- a/pkg/shell/pty.go +++ b/pkg/shell/pty.go @@ -69,22 +69,9 @@ func (t *Turn) Wait() { // Close 关闭 PTY 并终止子进程 func (t *Turn) Close() { _ = t.cmd.Process.Signal(syscall.SIGTERM) - - // 等待最多 10 秒 - done := make(chan struct{}) - go func() { - _ = t.cmd.Wait() - close(done) - }() - - select { - case <-done: - // 进程已退出 - case <-time.After(10 * time.Second): - // 超时,KILL - _ = t.cmd.Process.Kill() - } - + // 等待 10 秒 + time.Sleep(10 * time.Second) + _ = t.cmd.Process.Kill() _ = t.ptmx.Close() } diff --git a/pkg/ssh/turn.go b/pkg/ssh/turn.go index c2d644dd..a10c5743 100644 --- a/pkg/ssh/turn.go +++ b/pkg/ssh/turn.go @@ -64,22 +64,9 @@ func (t *Turn) Write(p []byte) (n int, err error) { func (t *Turn) Close() { _ = t.stdin.Close() _ = t.session.Signal(ssh.SIGTERM) - - // 等待最多 10 秒 - done := make(chan struct{}) - go func() { - _ = t.session.Wait() - close(done) - }() - - select { - case <-done: - // 会话已退出 - case <-time.After(10 * time.Second): - // 超时,KILL - _ = t.session.Signal(ssh.SIGKILL) - } - + // 等待 10 秒 + time.Sleep(10 * time.Second) + _ = t.session.Signal(ssh.SIGKILL) _ = t.session.Close() }