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
Next Next commit
mess around
  • Loading branch information
ammario committed Jun 8, 2023
commit a1b68e55996b986d8b24124a2511c6754865dcdc
21 changes: 14 additions & 7 deletions cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (r *RootCmd) ssh() *clibase.Cmd {
if logDirPath != "" {
nonce, err := cryptorand.StringCharset(cryptorand.Lower, 5)
if err != nil {
panic(err)
return xerrors.Errorf("generate nonce: %w", err)
}
logFilePath := filepath.Join(
logDirPath,
Expand Down Expand Up @@ -109,6 +109,19 @@ func (r *RootCmd) ssh() *clibase.Cmd {
client.Logger = logger
}

// This WaitGroup solves for a race condition where we were logging
// while closing the log file in in a defer. It probably solves
// others too.
//
// Its position in this function is important. It must be after
// the logger is created but before any goroutines or wind-down
// defers (e.g. context cancels) are declared.
var wg sync.WaitGroup
defer func() {
cancel()
wg.Wait()
}()

workspace, workspaceAgent, err := getWorkspaceAndAgent(ctx, inv, client, codersdk.Me, inv.Args[0])
if err != nil {
return err
Expand Down Expand Up @@ -169,12 +182,6 @@ func (r *RootCmd) ssh() *clibase.Cmd {
stopPolling := tryPollWorkspaceAutostop(ctx, client, workspace)
defer stopPolling()

// This WaitGroup solves for a race condition where we were logging
// while closing the log file in in a defer. It probably solves
// others too.
var wg sync.WaitGroup
defer wg.Wait()

if stdio {
rawSSH, err := conn.SSH(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cli/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ type stdioConn struct {
io.Writer
}

func (*stdioConn) Close() (err error) {
func (c *stdioConn) Close() (err error) {
return nil
}

Expand Down