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

fix: ssh会话连接泄露

This commit is contained in:
2025-11-23 03:03:56 +08:00
parent c60bba465d
commit ad3e375d33
5 changed files with 17 additions and 27 deletions

View File

@@ -3,7 +3,6 @@ package ssh
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
@@ -61,19 +60,19 @@ func (t *Turn) Write(p []byte) (n int, err error) {
return len(p), nil
}
func (t *Turn) Close() error {
if t.session != nil {
_ = t.session.Close()
}
return t.ws.CloseNow()
func (t *Turn) Close() {
_ = t.stdin.Close()
_ = t.session.Signal(ssh.SIGTERM)
_ = t.session.Close()
}
func (t *Turn) Handle(ctx context.Context) error {
var resize MessageResize
for {
select {
case <-ctx.Done():
return errors.New("ssh context done exit")
return ctx.Err()
default:
_, data, err := t.ws.Read(ctx)
if err != nil {
@@ -98,6 +97,6 @@ func (t *Turn) Handle(ctx context.Context) error {
}
}
func (t *Turn) Wait() error {
return t.session.Wait()
func (t *Turn) Wait() {
_ = t.session.Wait()
}