Skip to content

Commit 1a7fd26

Browse files
committed
Revert SSH conn handling
1 parent 9936923 commit 1a7fd26

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

agent/agent.go

+12-18
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,13 @@ func (a *agent) run(ctx context.Context) error {
268268

269269
scriptDone := make(chan error, 1)
270270
scriptStart := time.Now()
271-
err = a.trackConnGoroutine(func() {
271+
err := a.trackConnGoroutine(func() {
272272
defer close(scriptDone)
273273
scriptDone <- a.runStartupScript(ctx, metadata.StartupScript)
274274
})
275+
if err != nil {
276+
return xerrors.Errorf("track startup script: %w", err)
277+
}
275278
go func() {
276279
var timeout <-chan time.Time
277280
// If timeout is zero, an older version of the coder
@@ -645,24 +648,15 @@ func (a *agent) init(ctx context.Context) {
645648
sshLogger.Info(ctx, "ssh connection ended", slog.Error(err))
646649
},
647650
Handler: func(session ssh.Session) {
648-
err := a.trackConnGoroutine(func() {
649-
err := a.handleSSHSession(session)
650-
var exitError *exec.ExitError
651-
if xerrors.As(err, &exitError) {
652-
a.logger.Debug(ctx, "ssh session returned", slog.Error(exitError))
653-
_ = session.Exit(exitError.ExitCode())
654-
return
655-
}
656-
if err != nil {
657-
a.logger.Warn(ctx, "ssh session failed", slog.Error(err))
658-
// This exit code is designed to be unlikely to be confused for a legit exit code
659-
// from the process.
660-
_ = session.Exit(MagicSessionErrorCode)
661-
return
662-
}
663-
})
651+
err := a.handleSSHSession(session)
652+
var exitError *exec.ExitError
653+
if xerrors.As(err, &exitError) {
654+
a.logger.Debug(ctx, "ssh session returned", slog.Error(exitError))
655+
_ = session.Exit(exitError.ExitCode())
656+
return
657+
}
664658
if err != nil {
665-
a.logger.Warn(ctx, "track ssh session failed", slog.Error(err))
659+
a.logger.Warn(ctx, "ssh session failed", slog.Error(err))
666660
// This exit code is designed to be unlikely to be confused for a legit exit code
667661
// from the process.
668662
_ = session.Exit(MagicSessionErrorCode)

cli/root_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ ExtractCommandPathsLoop:
121121

122122
got := buf.Bytes()
123123
// Remove CRLF newlines (Windows).
124-
// got = bytes.ReplaceAll(got, []byte{'\r', '\n'}, []byte{'\n'})
124+
got = bytes.ReplaceAll(got, []byte{'\r', '\n'}, []byte{'\n'})
125125

126126
// The `coder templates create --help` command prints the path
127127
// to the working directory (--directory flag default value).

0 commit comments

Comments
 (0)