Skip to content

Commit 1affe97

Browse files
authored
Merge branch 'coder:main' into patch-1
2 parents b1f397c + b287ec5 commit 1affe97

File tree

8 files changed

+95
-7
lines changed

8 files changed

+95
-7
lines changed

agent/agent.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ func (a *agent) init(ctx context.Context) {
844844
_ = session.Exit(MagicSessionErrorCode)
845845
return
846846
}
847+
_ = session.Exit(0)
847848
},
848849
HostSigners: []ssh.Signer{randomSigner},
849850
LocalPortForwardingCallback: func(ctx ssh.Context, destinationHost string, destinationPort uint32) bool {
@@ -1100,7 +1101,9 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
11001101
if err != nil {
11011102
return xerrors.Errorf("start command: %w", err)
11021103
}
1104+
var wg sync.WaitGroup
11031105
defer func() {
1106+
defer wg.Wait()
11041107
closeErr := ptty.Close()
11051108
if closeErr != nil {
11061109
a.logger.Warn(ctx, "failed to close tty", slog.Error(closeErr))
@@ -1117,10 +1120,16 @@ func (a *agent) handleSSHSession(session ssh.Session) (retErr error) {
11171120
}
11181121
}
11191122
}()
1123+
// We don't add input copy to wait group because
1124+
// it won't return until the session is closed.
11201125
go func() {
11211126
_, _ = io.Copy(ptty.Input(), session)
11221127
}()
1128+
wg.Add(1)
11231129
go func() {
1130+
// Ensure data is flushed to session on command exit, if we
1131+
// close the session too soon, we might lose data.
1132+
defer wg.Done()
11241133
_, _ = io.Copy(session, ptty.Output())
11251134
}()
11261135
err = process.Wait()

agent/agent_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,57 @@ func TestAgent_Session_TTY_Hushlogin(t *testing.T) {
348348
require.NotContains(t, stdout.String(), wantNotMOTD, "should not show motd")
349349
}
350350

351+
func TestAgent_Session_TTY_FastCommandHasOutput(t *testing.T) {
352+
t.Parallel()
353+
if runtime.GOOS == "windows" {
354+
// This might be our implementation, or ConPTY itself.
355+
// It's difficult to find extensive tests for it, so
356+
// it seems like it could be either.
357+
t.Skip("ConPTY appears to be inconsistent on Windows.")
358+
}
359+
360+
// This test is here to prevent regressions where quickly executing
361+
// commands (with TTY) don't flush their output to the SSH session.
362+
//
363+
// See: https://github.com/coder/coder/issues/6656
364+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
365+
defer cancel()
366+
//nolint:dogsled
367+
conn, _, _, _, _ := setupAgent(t, agentsdk.Metadata{}, 0)
368+
sshClient, err := conn.SSHClient(ctx)
369+
require.NoError(t, err)
370+
defer sshClient.Close()
371+
372+
ptty := ptytest.New(t)
373+
374+
var stdout bytes.Buffer
375+
// NOTE(mafredri): Increase iterations to increase chance of failure,
376+
// assuming bug is present.
377+
// Using 1000 iterations is basically a guaranteed failure (but let's
378+
// not increase test times needlessly).
379+
for i := 0; i < 5; i++ {
380+
func() {
381+
stdout.Reset()
382+
383+
session, err := sshClient.NewSession()
384+
require.NoError(t, err)
385+
defer session.Close()
386+
err = session.RequestPty("xterm", 128, 128, ssh.TerminalModes{})
387+
require.NoError(t, err)
388+
389+
session.Stdout = &stdout
390+
session.Stderr = ptty.Output()
391+
session.Stdin = ptty.Input()
392+
err = session.Start("echo wazzup")
393+
require.NoError(t, err)
394+
395+
err = session.Wait()
396+
require.NoError(t, err)
397+
require.Contains(t, stdout.String(), "wazzup", "should output greeting")
398+
}()
399+
}
400+
}
401+
351402
//nolint:paralleltest // This test reserves a port.
352403
func TestAgent_TCPLocalForwarding(t *testing.T) {
353404
random, err := net.Listen("tcp", "127.0.0.1:0")

cli/cliui/cliui.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ var Styles = struct {
4949
Keyword: defaultStyles.Keyword,
5050
Paragraph: defaultStyles.Paragraph,
5151
Placeholder: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#585858", Dark: "#4d46b3"}),
52-
Prompt: defaultStyles.Prompt.Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}),
53-
FocusedPrompt: defaultStyles.FocusedPrompt.Foreground(lipgloss.Color("#651fff")),
52+
Prompt: defaultStyles.Prompt.Copy().Foreground(lipgloss.AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}),
53+
FocusedPrompt: defaultStyles.FocusedPrompt.Copy().Foreground(lipgloss.Color("#651fff")),
5454
Fuchsia: defaultStyles.SelectedMenuItem.Copy(),
55-
Logo: defaultStyles.Logo.SetString("Coder"),
55+
Logo: defaultStyles.Logo.Copy().SetString("Coder"),
5656
Warn: lipgloss.NewStyle().Foreground(
5757
lipgloss.AdaptiveColor{Light: "#04B575", Dark: "#ECFD65"},
5858
),

coderd/provisionerjobs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ func (api *API) followProvisionerJobLogs(actor rbac.Subject, jobID uuid.UUID) (<
347347
logger := api.Logger.With(slog.F("job_id", jobID))
348348

349349
var (
350-
bufferedLogs = make(chan *database.ProvisionerJobLog, 128)
350+
// With debug logging enabled length = 128 is insufficient
351+
bufferedLogs = make(chan *database.ProvisionerJobLog, 1024)
351352
endOfLogs atomic.Bool
352353
lastSentLogID atomic.Int64
353354
)

docs/install/docker.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ You can install and run Coder using the official Docker images published on [Git
44

55
Docker is required. See the [official installation documentation](https://docs.docker.com/install/).
66

7+
> Note that the below steps are only supported on a Linux distribution. If on macOS, please [run Coder via the standalone binary](./binary.md).
8+
79
## Run Coder with the built-in database (quick)
810

911
For proof-of-concept deployments, you can run a complete Coder instance with
10-
the following command:
12+
the following command.
1113

1214
```console
1315
export CODER_DATA=$HOME/.config/coderv2-docker

provisioner/terraform/executor.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,27 @@ func readAndLog(sink logSink, r io.Reader, done chan<- any, level proto.LogLevel
460460
defer close(done)
461461
scanner := bufio.NewScanner(r)
462462
for scanner.Scan() {
463-
sink.Log(&proto.Log{Level: level, Output: scanner.Text()})
463+
var log terraformProvisionLog
464+
err := json.Unmarshal(scanner.Bytes(), &log)
465+
if err != nil {
466+
if strings.TrimSpace(scanner.Text()) == "" {
467+
continue
468+
}
469+
470+
sink.Log(&proto.Log{Level: level, Output: scanner.Text()})
471+
continue
472+
}
473+
474+
logLevel := convertTerraformLogLevel(log.Level, sink)
475+
if logLevel == proto.LogLevel_TRACE {
476+
continue // skip TRACE log entries as they produce a lot of noise
477+
}
478+
479+
// Degrade JSON log entries marked as INFO as these are logs produced in debug mode.
480+
if logLevel == proto.LogLevel_INFO {
481+
logLevel = proto.LogLevel_DEBUG
482+
}
483+
sink.Log(&proto.Log{Level: logLevel, Output: log.Message})
464484
}
465485
}
466486

provisioner/terraform/provision.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ func provisionEnv(config *proto.Provision_Config, params []*proto.ParameterValue
236236
for _, gitAuth := range gitAuth {
237237
env = append(env, provider.GitAuthAccessTokenEnvironmentVariable(gitAuth.Id)+"="+gitAuth.AccessToken)
238238
}
239+
// FIXME env = append(env, "TF_LOG=JSON")
239240
return env, nil
240241
}
241242

site/src/components/Logs/Logs.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ const useStyles = makeStyles<
108108
backgroundColor: theme.palette.error.dark,
109109
},
110110

111-
"&.warning": {
111+
"&.debug": {
112+
backgroundColor: theme.palette.grey[900],
113+
},
114+
115+
"&.warn": {
112116
backgroundColor: theme.palette.warning.dark,
113117
},
114118
},

0 commit comments

Comments
 (0)