From b4c238b7a5c9deaba07dca1bdda31d240b3212a3 Mon Sep 17 00:00:00 2001 From: Rangel Dokov Date: Fri, 13 Jan 2023 17:32:19 +0000 Subject: [PATCH] Avoid double sending of SIGINT to subprocesses Standard bash behavior when pressing Ctrl+C is to send SIGINT to the foreground process group. This combines well with standard fork behavior because subprocesses are started in the same group, so a multi-process program is correctly terminated without any explicit signal handling. It however does not work well in cases where signals are handled explicitly like here, because on Ctrl+C the subprocesses receive two SIGINTs - one directly from the shell and one from the interrupt handler in the `CLI` class. This in turn can prevent graceful shutdown in the subprocesses. The specific example that prompted this fix was interrupting feature specs using selenium. In case of a double interrupt the browser process will sometimes remain running after rspec is terminated. --- lib/parallel_tests/test/runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parallel_tests/test/runner.rb b/lib/parallel_tests/test/runner.rb index 90007bfe..38990d39 100644 --- a/lib/parallel_tests/test/runner.rb +++ b/lib/parallel_tests/test/runner.rb @@ -110,7 +110,7 @@ def print_command(command, env) def execute_command_and_capture_output(env, cmd, options) pid = nil - popen_options = {} + popen_options = { pgroup: true } popen_options[:err] = [:child, :out] if options[:combine_stderr] output = IO.popen(env, cmd, popen_options) do |io|