2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 11:27:17 +08:00

fix: 修复 PTY Websocket 客户端断开连接后命令仍在后台运行的问题 (#1222)

* Initial plan

* fix: 修复 PTY Websocket 客户端断开连接后命令仍在后台运行的问题

Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>

* fix: 解决连接中断后命令不被杀死的问题

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: devhaozi <115467771+devhaozi@users.noreply.github.com>
Co-authored-by: 耗子 <haozi@loli.email>
This commit is contained in:
Copilot
2026-01-12 04:13:04 +08:00
committed by GitHub
parent f9cda73981
commit ddfcd3e45c
4 changed files with 64 additions and 12 deletions

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"time"
"github.com/coder/websocket"
"golang.org/x/crypto/ssh"
@@ -63,6 +64,22 @@ 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)
}
_ = t.session.Close()
}