Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Avoid resize errors on close
  • Loading branch information
mafredri committed Mar 29, 2023
commit a3c01b9b8bb49f83e16c03cc02a8566dafdb6717
13 changes: 7 additions & 6 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,8 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
go func() {
for win := range windowSize {
resizeErr := ptty.Resize(uint16(win.Height), uint16(win.Width))
if resizeErr != nil {
// If the pty is closed, then command has exited, no need to log.
if resizeErr != nil && !errors.Is(resizeErr, pty.ErrClosed) {
a.logger.Warn(ctx, "failed to resize tty", slog.Error(resizeErr))
}
}
Expand Down Expand Up @@ -1189,6 +1190,11 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
return cmd.Wait()
}

type readNopCloser struct{ io.Reader }

// Close implements io.Closer.
func (readNopCloser) Close() error { return nil }

func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, msg codersdk.WorkspaceAgentReconnectingPTYInit, conn net.Conn) (retErr error) {
defer conn.Close()

Expand Down Expand Up @@ -1385,11 +1391,6 @@ func (a *agent) handleReconnectingPTY(ctx context.Context, logger slog.Logger, m
}
}

type readNopCloser struct{ io.Reader }

// Close implements io.Closer.
func (readNopCloser) Close() error { return nil }

// startReportingConnectionStats runs the connection stats reporting goroutine.
func (a *agent) startReportingConnectionStats(ctx context.Context) {
reportStats := func(networkStats map[netlogtype.Connection]netlogtype.Counts) {
Expand Down
4 changes: 4 additions & 0 deletions pty/pty.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import (
"os"

"github.com/gliderlabs/ssh"
"golang.org/x/xerrors"
)

// ErrClosed is returned when a PTY is used after it has been closed.
var ErrClosed = xerrors.New("pty: closed")

// PTY is a minimal interface for interacting with a TTY.
type PTY interface {
io.Closer
Expand Down
3 changes: 1 addition & 2 deletions pty/pty_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/creack/pty"
"github.com/u-root/u-root/pkg/termios"
"golang.org/x/sys/unix"
"golang.org/x/xerrors"
)

func newPty(opt ...Option) (retPTY *otherPty, err error) {
Expand Down Expand Up @@ -146,7 +145,7 @@ func (p *otherPty) Close() error {
if err != nil {
p.err = err
} else {
p.err = xerrors.New("pty: closed")
p.err = ErrClosed
}

return err
Expand Down