summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyril Brulebois <ckb@riseup.net>2019-01-10 20:08:48 +0100
committerintrigeri <intrigeri@boum.org>2019-04-14 07:19:29 +0000
commitcc86a75fe6fdbb5ac54714d62f4b8dfe5831eb80 (patch)
treeadd1250070c054a534c7dee98035d018deb31af8
parent774b3f6090b56a2640ea5efb4f1fee21c818e8b1 (diff)
Avoid zombies by reaping all child processes (refs: #14948).bugfix/14948-avoid-zombies-in-testsuite-runs+force-all-tests
IO.popen makes it possible to start a command as a child process but it won't automatically reap the subprocess when it exits, leading to many zombies when running the automated test suite. Fix this in several ways depending on the call site: * Create an intermediary variable to hold the subprocess returned by IO.popen, making it possible to read its standard output, but also allowing to call its close method afterwards. This is less straightforward than a IO.popen().gets call, but allows for appropriate clean-up. * When the subprocess object itself (p) is available, add a "p.close" call after killing it through "Process.kill(signal, p.pid)". * Otherwise, when only the pid of the subprocess is available, call "Process.wait(pid)" after killing it.
-rw-r--r--features/step_definitions/chutney.rb1
-rw-r--r--features/step_definitions/common_steps.rb2
-rw-r--r--features/step_definitions/erase_memory.rb5
-rw-r--r--features/support/helpers/chatbot_helper.rb1
-rw-r--r--features/support/helpers/sniffing_helper.rb1
-rw-r--r--features/support/helpers/sshd_helper.rb1
-rw-r--r--features/support/hooks.rb1
7 files changed, 10 insertions, 2 deletions
diff --git a/features/step_definitions/chutney.rb b/features/step_definitions/chutney.rb
index 11a65f1..e068814 100644
--- a/features/step_definitions/chutney.rb
+++ b/features/step_definitions/chutney.rb
@@ -162,6 +162,7 @@ def chutney_onionservice_redir(remote_address, remote_port)
kill_redir = Proc.new do
begin
Process.kill("TERM", $chutney_onionservice_job.pid)
+ $chutney_onionservice_job.close
rescue
# noop
end
diff --git a/features/step_definitions/common_steps.rb b/features/step_definitions/common_steps.rb
index 4f5601a..ac90d0b 100644
--- a/features/step_definitions/common_steps.rb
+++ b/features/step_definitions/common_steps.rb
@@ -863,7 +863,7 @@ EOF
Process.kill(0, proc.pid) == 1
end
- add_after_scenario_hook { Process.kill("TERM", proc.pid) }
+ add_after_scenario_hook { Process.kill("TERM", proc.pid); proc.close }
# It seems necessary to actually check that the LAN server is
# serving, possibly because it isn't doing so reliably when setting
diff --git a/features/step_definitions/erase_memory.rb b/features/step_definitions/erase_memory.rb
index 5ba9487..b1db251 100644
--- a/features/step_definitions/erase_memory.rb
+++ b/features/step_definitions/erase_memory.rb
@@ -43,7 +43,10 @@ def pattern_coverage_in_guest_ram(reference_memory_b)
FileUtils.touch(dump)
FileUtils.chmod(0666, dump)
$vm.domain.core_dump(dump)
- patterns = IO.popen(['grep', '--text', '-c', 'wipe_didnt_work', dump]).gets.to_i
+ # Make sure to close after reading stdout, to avoid Zombies:
+ grep = IO.popen(['grep', '--text', '-c', 'wipe_didnt_work', dump])
+ patterns = grep.gets.to_i
+ grep.close
File.delete dump
# Pattern is 16 bytes long
patterns_b = patterns*16
diff --git a/features/support/helpers/chatbot_helper.rb b/features/support/helpers/chatbot_helper.rb
index 23ce3e1..6bee74b 100644
--- a/features/support/helpers/chatbot_helper.rb
+++ b/features/support/helpers/chatbot_helper.rb
@@ -37,6 +37,7 @@ class ChatBot
@otr_key_file.delete
begin
Process.kill("TERM", @pid)
+ Process.wait(@pid)
rescue
# noop
end
diff --git a/features/support/helpers/sniffing_helper.rb b/features/support/helpers/sniffing_helper.rb
index 38b1382..ca9fa27 100644
--- a/features/support/helpers/sniffing_helper.rb
+++ b/features/support/helpers/sniffing_helper.rb
@@ -40,6 +40,7 @@ class Sniffer
def stop
begin
Process.kill("TERM", @pid)
+ Process.wait(@pid)
rescue
# noop
end
diff --git a/features/support/helpers/sshd_helper.rb b/features/support/helpers/sshd_helper.rb
index 2e0069c..a3814fe 100644
--- a/features/support/helpers/sshd_helper.rb
+++ b/features/support/helpers/sshd_helper.rb
@@ -46,6 +46,7 @@ EOF
File.delete("#{$config['TMPDIR']}/ssh.pid")
begin
Process.kill("TERM", @pid)
+ Process.wait(@pid)
rescue
# noop
end
diff --git a/features/support/hooks.rb b/features/support/hooks.rb
index 3983d1f..43c84f3 100644
--- a/features/support/hooks.rb
+++ b/features/support/hooks.rb
@@ -259,6 +259,7 @@ After('@product') do |scenario|
# what the error was.
sleep 3 if scenario.failed?
Process.kill("INT", @video_capture_pid)
+ Process.wait(@video_capture_pid)
save_failure_artifact("Video", @video_path)
end
if scenario.failed?