Skip to content

fix: Close tty first in ptytest cleanup #5252

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 2, 2022
Merged
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
22 changes: 20 additions & 2 deletions pty/ptytest/ptytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,29 @@ func create(t *testing.T, ptty pty.PTY, name string) *PTY {
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
defer cancel()

_ = out.Close()
_ = ptty.Close()
errC := make(chan error, 2)
doClose := func(c io.Closer) {
select {
case <-ctx.Done():
case errC <- c.Close():
}
}
// Close the tty asynchronously to allow the select below to timeout.
go func() {
// Close the tty first so allow out to consume its last bytes.
doClose(ptty)
doClose(out)
}()

More:
select {
case <-ctx.Done():
fatalf(t, name, "cleanup", "copy did not close in time")
case err := <-errC:
if err != nil {
logf(t, name, "copy close error: %v", err)
}
goto More
case <-copyDone:
}
})
Expand Down