Skip to content
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

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

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

juster
Copy link
Contributor

@juster juster commented Oct 8, 2023

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 juster force-pushed the pipe_to_cmd_test_race branch from d03f623 to bf01e96 Compare October 8, 2023 02:47
@juster
Copy link
Contributor Author

juster commented Oct 8, 2023

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.

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.

Fix this by forcing the spawned "sh" command to read a line of
input before exiting or sending a signal to itself.

Automated tests ran into another problem:

The windows GitHub runner installs gawk using Chocolatey and this
package of gawk does not use "sh" to execute commands, instead it
uses "cmd.exe". Because "read" is a "sh" builtin command this will
not work for windows tests of gawk and probably other awks.
@juster juster force-pushed the pipe_to_cmd_test_race branch from bf01e96 to 0f519b8 Compare October 15, 2023 16:16
@juster
Copy link
Contributor Author

juster commented Oct 15, 2023

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 benhoyt merged commit 1564ef8 into benhoyt:master Oct 16, 2023
10 checks passed
@benhoyt
Copy link
Owner

benhoyt commented Oct 16, 2023

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants