Skip to content

Commit

Permalink
Fix zombie phantomjs processes (#338)
Browse files Browse the repository at this point in the history
After running wallaby as part of a separate application, I confirmed we
were still leaving around zombie phantom processes. It turns out if we
kill the script's process group, it will kill all of the child processes
as well. This appears to fix the zombie issue once and for all.

One thing to note, I kill the process group by using the negative value
of the wrapper script's pid, instead of using `ps axo pid, pgid` to look
up the process group id. This is because I was occasionally running into
issues where the process group lookup wasn't returning a result, causing
more zombie processes. Hopefully this approach won't cause any issues.

Fixes #224.
  • Loading branch information
aaronrenner authored and keathley committed Feb 12, 2018
1 parent 29aed59 commit 08875e7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions priv/run_phantom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

set -e

script_status="running"

create_pipe(){
local pipe=$(mktemp -u)
mkfifo -m 600 "$pipe"
Expand Down Expand Up @@ -39,10 +41,13 @@ shutdown(){
local my_pid=$1
local program_pid=$2

children=$(ps xao pid,pgid | grep $my_pid | awk '{print $1}' | grep -v $my_pid)
kill $program_pid 2>/dev/null
if [ $script_status = "running" ]; then
script_status="shutting down"

# Kill this script's process group
kill -TERM $(($my_pid * -1)) 2>/dev/null
fi

wait_for_pids_to_exit $children
exit 0
}

Expand Down

0 comments on commit 08875e7

Please sign in to comment.