benhoyt / goawk

A POSIX-compliant AWK interpreter written in Go, with CSV support
https://benhoyt.com/writings/goawk/
MIT License
1.94k stars 84 forks source link

Fix rare race in pipe-to-command close() result test #213

Closed juster closed 1 year ago

juster commented 1 year ago

Here a fix for the test race condition in #206 and the test fail for Linux:

https://github.com/benhoyt/goawk/actions/runs/6293036690/job/17083040381.

I was able to reproduce on my older Macbook and Go 1.17 using go test -count 1000 -run='TestInterp/^BEGIN { cmd'... but not consistently. In my case the other pipe-to-command test failed (the one which uses /bin/kill) but with the same pipe error.

Analysis/commit message follows:

The bufio.Writer does not write to the Cmd pipe until Flush is called when the Cmd is Wait-ed on. This causes a Flush error but not a Wait error. This only happens if the Cmd starts and exits before the Flush can be called by goawk.

juster commented 1 year ago

I fixed a Linux test failure which was caused by using sh's (technically bash's) read with no arguments. But Windows is a puzzle to me, since it has no read builtin at all. I'm out of time tonight I'll have to come back to this later.

juster commented 1 year ago

I looked at this today and it was more obvious what the problem was. The gawk installed with chocolatey on the windows runner does not run command pipes using sh.exe. Instead it runs commands with cmd.exe.

I skipped the test which uses the read shell command by using !windows-gawk.

benhoyt commented 1 year ago

Thanks!