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
Fix race
  • Loading branch information
ammario committed Jun 6, 2023
commit 82ce7a21410c038d8c83e3bd1e16311df125e876
14 changes: 12 additions & 2 deletions cli/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,18 @@ func (r *RootCmd) ssh() *clibase.Cmd {
if err != nil {
return xerrors.Errorf("error opening %s for logging: %w", logFilePath, err)
}
logger = slog.Make(sloghuman.Sink(logFile))
defer logFile.Close()
// HACK: Something was keeping a reference to this file
// after the goroutine ends, leading to the race observed
// here: https://github.com/coder/coder/actions/runs/5178818818/jobs/9331016395.
rd, wr := io.Pipe()
go func() {
_, _ = io.Copy(logFile, rd)
}()
defer func() {
_ = wr.Close()
_ = logFile.Close()
}()
logger = slog.Make(sloghuman.Sink(wr))
if r.verbose {
logger = logger.Leveled(slog.LevelDebug)
}
Expand Down
4 changes: 3 additions & 1 deletion cli/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,12 @@ func TestSSH(t *testing.T) {
pty.WriteLine("exit")
<-cmdDone

_, err := os.Stat(logFile)
info, err := os.Stat(logFile)
if err != nil {
t.Fatalf("failed to find ssh logfile: %v", err)
}

require.Greater(t, info.Size(), int64(0), "ssh logfile is empty")
})
}

Expand Down
22 changes: 6 additions & 16 deletions docs/cli/ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,14 @@ Specifies whether to forward the GPG agent. Unsupported on Windows workspaces, b

Specifies which identity agent to use (overrides $SSH_AUTH_SOCK), forward agent must also be enabled.

### --log-dir
### -l, --log-file

| | |
| ----------- | ------------------------------- |
| Type | <code>string</code> |
| Environment | <code>$CODER_SSH_LOG_DIR</code> |
| Default | <code>/tmp</code> |

Specify the location for the log files.

### -l, --log-to-file

| | |
| ----------- | ----------------------------------- |
| Type | <code>bool</code> |
| Environment | <code>$CODER_SSH_LOG_TO_FILE</code> |
| | |
| ----------- | -------------------------------- |
| Type | <code>string</code> |
| Environment | <code>$CODER_SSH_LOG_FILE</code> |

Enable diagnostic logging to file.
Specify the location of an SSH diagnostic log file.

### --no-wait

Expand Down