...
 
Commits (1)
  • Cyril Brulebois's avatar
    Avoid zombies by reaping all child processes (refs: #14948). · cc86a75f
    Cyril Brulebois authored
    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.
    cc86a75f
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -37,6 +37,7 @@ class ChatBot
@otr_key_file.delete
begin
Process.kill("TERM", @pid)
Process.wait(@pid)
rescue
# noop
end
......
......@@ -40,6 +40,7 @@ class Sniffer
def stop
begin
Process.kill("TERM", @pid)
Process.wait(@pid)
rescue
# noop
end
......
......@@ -46,6 +46,7 @@ EOF
File.delete("#{$config['TMPDIR']}/ssh.pid")
begin
Process.kill("TERM", @pid)
Process.wait(@pid)
rescue
# noop
end
......
......@@ -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?
......