mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 07:57:21 +08:00
fix: 解决连接中断后命令不被杀死的问题
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user