File tree 2 files changed +19
-6
lines changed
2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -457,7 +457,7 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
457
457
for win := range windowSize {
458
458
resizeErr := ptty .Resize (uint16 (win .Height ), uint16 (win .Width ))
459
459
if resizeErr != nil {
460
- a .logger .Warn (context .Background (), "failed to resize tty" , slog .Error (err ))
460
+ a .logger .Warn (context .Background (), "failed to resize tty" , slog .Error (resizeErr ))
461
461
}
462
462
}
463
463
}()
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
"sync"
11
11
12
12
"github.com/creack/pty"
13
+ "golang.org/x/xerrors"
13
14
)
14
15
15
16
func newPty () (PTY , error ) {
@@ -26,6 +27,8 @@ func newPty() (PTY, error) {
26
27
27
28
type otherPty struct {
28
29
mutex sync.Mutex
30
+ closed bool
31
+ err error
29
32
pty , tty * os.File
30
33
}
31
34
@@ -55,6 +58,9 @@ func (p *otherPty) Output() ReadWriter {
55
58
func (p * otherPty ) Resize (height uint16 , width uint16 ) error {
56
59
p .mutex .Lock ()
57
60
defer p .mutex .Unlock ()
61
+ if p .closed {
62
+ return p .err
63
+ }
58
64
return pty .Setsize (p .pty , & pty.Winsize {
59
65
Rows : height ,
60
66
Cols : width ,
@@ -65,17 +71,24 @@ func (p *otherPty) Close() error {
65
71
p .mutex .Lock ()
66
72
defer p .mutex .Unlock ()
67
73
74
+ if p .closed {
75
+ return p .err
76
+ }
77
+ p .closed = true
78
+
68
79
err := p .pty .Close ()
80
+ err2 := p .tty .Close ()
69
81
if err != nil {
70
- _ = p .tty .Close ()
71
- return err
82
+ err = err2
72
83
}
73
84
74
- err = p .tty .Close ()
75
85
if err != nil {
76
- return err
86
+ p .err = err
87
+ } else {
88
+ p .err = xerrors .New ("pty: closed" )
77
89
}
78
- return nil
90
+
91
+ return err
79
92
}
80
93
81
94
func (p * otherProcess ) Wait () error {
You can’t perform that action at this time.
0 commit comments