From e3ce6cf17b8453fa4ac8789063713f8de5741de5 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Thu, 11 Jun 2020 19:05:19 +0200 Subject: [PATCH] Detach bisect process to avoid making zombie process If we do not `waitpid` or `detach` the bisect process become a zombie process. As mentionned in waitpid doc: > As long as a zombie is not removed from the system via a wait, it will consume a slot in the kernel process table, and if this table fills, it will not be possible to create further processes. `detach` is a good idea. From the Ruby doc: > Some operating systems retain the status of terminated child processes until the parent collects that status (normally using some variant of wait()). If the parent never collects this status, the child stays around as a zombie process. Process::detach prevents this by setting up a separate Ruby thread whose sole job is to reap the status of the process pid when it terminates. Use detach only when you do not intend to explicitly wait for the child to terminate. Related: - https://github.com/rspec/rspec-core/pull/2669 - https://andrykonchin.github.io/rails/2019/12/25/deadlock-in-rspec.html --- lib/rspec/core/bisect/fork_runner.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/rspec/core/bisect/fork_runner.rb b/lib/rspec/core/bisect/fork_runner.rb index ced21c96e6..b9c16b0233 100644 --- a/lib/rspec/core/bisect/fork_runner.rb +++ b/lib/rspec/core/bisect/fork_runner.rb @@ -91,9 +91,12 @@ def initialize(runner, channel) end def dispatch_specs(run_descriptor) - fork { run_specs(run_descriptor) } + pid = fork { run_specs(run_descriptor) } # We don't use Process.waitpid here as it was causing bisects to - # block due to the file descriptor limit on OSX / Linux. + # block due to the file descriptor limit on OSX / Linux. We need + # to detach the process to avoid having zombie process and consume + # slot in the kernel process table. + Process.detach(pid) end private