- Notifications
You must be signed in to change notification settings - Fork928
fix(agent): Prevent SSH TTYs from losing command output on exit#6777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletionsagent/agent.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletionsagent/agent_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -348,6 +348,57 @@ func TestAgent_Session_TTY_Hushlogin(t *testing.T) { | ||
require.NotContains(t,stdout.String(),wantNotMOTD,"should not show motd") | ||
} | ||
funcTestAgent_Session_TTY_FastCommandHasOutput(t*testing.T) { | ||
t.Parallel() | ||
ifruntime.GOOS=="windows" { | ||
// This might be our implementation, or ConPTY itself. | ||
// It's difficult to find extensive tests for it, so | ||
// it seems like it could be either. | ||
t.Skip("ConPTY appears to be inconsistent on Windows.") | ||
} | ||
// This test is here to prevent regressions where quickly executing | ||
// commands (with TTY) don't flush their output to the SSH session. | ||
// | ||
// See: https://github.com/coder/coder/issues/6656 | ||
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong) | ||
defercancel() | ||
//nolint:dogsled | ||
conn,_,_,_,_:=setupAgent(t, agentsdk.Metadata{},0) | ||
sshClient,err:=conn.SSHClient(ctx) | ||
require.NoError(t,err) | ||
defersshClient.Close() | ||
ptty:=ptytest.New(t) | ||
varstdout bytes.Buffer | ||
// NOTE(mafredri): Increase iterations to increase chance of failure, | ||
// assuming bug is present. | ||
// Using 1000 iterations is basically a guaranteed failure (but let's | ||
// not increase test times needlessly). | ||
Comment on lines +375 to +378 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I really enjoy comments like this. I should do more of these! | ||
fori:=0;i<5;i++ { | ||
func() { | ||
stdout.Reset() | ||
session,err:=sshClient.NewSession() | ||
require.NoError(t,err) | ||
defersession.Close() | ||
err=session.RequestPty("xterm",128,128, ssh.TerminalModes{}) | ||
require.NoError(t,err) | ||
session.Stdout=&stdout | ||
session.Stderr=ptty.Output() | ||
session.Stdin=ptty.Input() | ||
err=session.Start("echo wazzup") | ||
require.NoError(t,err) | ||
err=session.Wait() | ||
require.NoError(t,err) | ||
require.Contains(t,stdout.String(),"wazzup","should output greeting") | ||
}() | ||
} | ||
} | ||
//nolint:paralleltest // This test reserves a port. | ||
funcTestAgent_TCPLocalForwarding(t*testing.T) { | ||
random,err:=net.Listen("tcp","127.0.0.1:0") | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.