Skip to content

Commit a1b68e5

Browse files
committed
mess around
1 parent 3c43cfc commit a1b68e5

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

cli/ssh.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
7676
if logDirPath != "" {
7777
nonce, err := cryptorand.StringCharset(cryptorand.Lower, 5)
7878
if err != nil {
79-
panic(err)
79+
return xerrors.Errorf("generate nonce: %w", err)
8080
}
8181
logFilePath := filepath.Join(
8282
logDirPath,
@@ -109,6 +109,19 @@ func (r *RootCmd) ssh() *clibase.Cmd {
109109
client.Logger = logger
110110
}
111111

112+
// This WaitGroup solves for a race condition where we were logging
113+
// while closing the log file in in a defer. It probably solves
114+
// others too.
115+
//
116+
// Its position in this function is important. It must be after
117+
// the logger is created but before any goroutines or wind-down
118+
// defers (e.g. context cancels) are declared.
119+
var wg sync.WaitGroup
120+
defer func() {
121+
cancel()
122+
wg.Wait()
123+
}()
124+
112125
workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, codersdk.Me, inv.Args[0])
113126
if err != nil {
114127
return err
@@ -169,12 +182,6 @@ func (r *RootCmd) ssh() *clibase.Cmd {
169182
stopPolling := tryPollWorkspaceAutostop(ctx, client, workspace)
170183
defer stopPolling()
171184

172-
// This WaitGroup solves for a race condition where we were logging
173-
// while closing the log file in in a defer. It probably solves
174-
// others too.
175-
var wg sync.WaitGroup
176-
defer wg.Wait()
177-
178185
if stdio {
179186
rawSSH, err := conn.SSH(ctx)
180187
if err != nil {

cli/ssh_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ type stdioConn struct {
714714
io.Writer
715715
}
716716

717-
func (*stdioConn) Close() (err error) {
717+
func (c *stdioConn) Close() (err error) {
718718
return nil
719719
}
720720

0 commit comments

Comments
 (0)