From c3054dcb919d31b9d589897c5ee1b8a610dad69c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Mon, 12 Jan 2026 04:16:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E4=B8=AD=E6=96=AD=E5=90=8E=E5=91=BD=E4=BB=A4=E4=B8=8D=E8=A2=AB?= =?UTF-8?q?=E6=9D=80=E6=AD=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/shell/pty.go | 19 +++---------------- pkg/ssh/turn.go | 19 +++---------------- 2 files changed, 6 insertions(+), 32 deletions(-) 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() }