Use exec in Bash launcher template
#518
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
bazel test, in macOS/Linux, all test rules are run under a script calledtest-setup.sh. This script does some extra work related to tests, and one of its tasks is cleaning up the remaining processes in the process group when the main test process exits.When the user cancels a
bazel test(orbuildfor that matter) invocation using Ctrl+C, Bazel sends SIGTERM to all running processes. SIGTERM is then forwarded fromtest-setup.shto all processes in the process group, and the script then waits for the test executable to exit. However, these two features interact badly when the test executable is Bash: the default behavior for SIGTERM in Bash is to exit immediately (for SIGINT and SIGQUIT Bash does something called "cooperative exit" where it waits for subprocesses to exit first before exiting itself). Because the Bash process is the test executable that is being waited on, this meanstest-setup.shprematurely detects the entire test as having exited and cleans up by sending SIGKILL to the remaining processes in the process group, which means any cleanup actions by the C# process are preempted.To ensure that
test-setup.shonly performs cleanup when the test itself exits, we useexecso that the Bash process is replaced withdotnet execwhich will only exit after the C# process itself handles the signal. This is fine since thedotnet execcommand is the last command in the template.I don't know how all of this behaves on Windows so I didn't touch the Windows template.