Skip to content

Commit 5a8fbb0

Browse files
committed
os: do not close syscall.Stdin in TestReadStdin
By calling NewConsoleFile on syscall.Stdin, we wind up closing it when the function returns, which causes errors when all the tests are run in a loop. To fix this, we instead create a duplicate handle of stdin. Fixes #43720. Change-Id: Ie6426e6306c7e1e39601794f4ff48bbf2fe67502 Reviewed-on: https://go-review.googlesource.com/c/go/+/284140 Run-TryBot: Jason A. Donenfeld <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Trust: Jason A. Donenfeld <[email protected]>
1 parent 682a1d2 commit 5a8fbb0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/os/os_windows_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,16 @@ func TestReadStdin(t *testing.T) {
692692
poll.ReadConsole = old
693693
}()
694694

695-
testConsole := os.NewConsoleFile(syscall.Stdin, "test")
695+
p, err := syscall.GetCurrentProcess()
696+
if err != nil {
697+
t.Fatalf("Unable to get handle to current process: %v", err)
698+
}
699+
var stdinDuplicate syscall.Handle
700+
err = syscall.DuplicateHandle(p, syscall.Handle(syscall.Stdin), p, &stdinDuplicate, 0, false, syscall.DUPLICATE_SAME_ACCESS)
701+
if err != nil {
702+
t.Fatalf("Unable to duplicate stdin: %v", err)
703+
}
704+
testConsole := os.NewConsoleFile(stdinDuplicate, "test")
696705

697706
var tests = []string{
698707
"abc",

0 commit comments

Comments
 (0)