commit 29797a33ecee1c6fc4882fc2b6beabcd64f554ce Author: David Fifield david@bamsoftware.com Date: Fri Apr 19 00:01:43 2019 -0600
Have terminateprocess-buffer wait on either of stdin closing or child exiting.
On Windows, I observed once that if meek-client.exe can't be found, tor.exe and its child process terminateprocess-buffer.exe continued running. I suspect terminateprocess-buffer was hung up in io.Copy--the child process stdin pipe was closed, but as it has nothing to copy, it couldn't detect the fact. Now have it do the stdin copy in a separate goroutine, and also close the child stdin pipe explicitly. --- terminateprocess-buffer/terminateprocess-buffer.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/terminateprocess-buffer/terminateprocess-buffer.go b/terminateprocess-buffer/terminateprocess-buffer.go index 85df446..afedc77 100644 --- a/terminateprocess-buffer/terminateprocess-buffer.go +++ b/terminateprocess-buffer/terminateprocess-buffer.go @@ -42,7 +42,16 @@ func main() { if err != nil { log.Fatal(err) } - io.Copy(stdin, os.Stdin) + go func() { + _, err := io.Copy(stdin, os.Stdin) + if err != nil { + log.Fatalf("copying stdin: %v", err) + } + err = stdin.Close() + if err != nil { + log.Fatalf("closing stdin: %v", err) + } + }() err = cmd.Wait() if err != nil { log.Fatal(err)