From: Jason A. Donenfeld Date: Mon, 18 Jan 2021 12:31:28 +0000 (+0100) Subject: os: do not close syscall.Stdin in TestReadStdin X-Git-Tag: go1.16rc1~68 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5a8fbb0d2d339fa87a02c0794f5a92c1ce121631;p=gostls13.git 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 TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: Jason A. Donenfeld --- diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go index 8d1d1f61b2..b0929b4f30 100644 --- a/src/os/os_windows_test.go +++ b/src/os/os_windows_test.go @@ -692,7 +692,16 @@ func TestReadStdin(t *testing.T) { poll.ReadConsole = old }() - testConsole := os.NewConsoleFile(syscall.Stdin, "test") + p, err := syscall.GetCurrentProcess() + if err != nil { + t.Fatalf("Unable to get handle to current process: %v", err) + } + var stdinDuplicate syscall.Handle + err = syscall.DuplicateHandle(p, syscall.Handle(syscall.Stdin), p, &stdinDuplicate, 0, false, syscall.DUPLICATE_SAME_ACCESS) + if err != nil { + t.Fatalf("Unable to duplicate stdin: %v", err) + } + testConsole := os.NewConsoleFile(stdinDuplicate, "test") var tests = []string{ "abc",