Skip to content

Commit

Permalink
[AIRFLOW-721] Descendant process can disappear before termination
Browse files Browse the repository at this point in the history
There is a race condition in helpers.py's
kill_descendant_processes
that checks for running processes and then tries
to terminate them.
This is not done atomically allowing for a small
window where a PID
can disappear before termination.

Closes apache#1963 from bolkedebruin/AIRFLOW-721
  • Loading branch information
bolkedebruin authored and alexvanboxel committed Dec 29, 2016
1 parent ed8e15b commit f048e94
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions airflow/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,16 @@ def kill_descendant_processes(logger, pids_to_kill=None):
logger.warn("Terminating descendant processes of {} PID: {}"
.format(this_process.cmdline(),
this_process.pid))
for descendant in descendant_processes:

temp_processes = descendant_processes[:]
for descendant in temp_processes:
logger.warn("Terminating descendant process {} PID: {}"
.format(descendant.cmdline(), descendant.pid))
descendant.terminate()
try:
descendant.terminate()
except psutil.NoSuchProcess:
descendant_processes.remove(descendant)

logger.warn("Waiting up to {}s for processes to exit..."
.format(TIME_TO_WAIT_AFTER_SIGTERM))
try:
Expand All @@ -228,8 +234,11 @@ def kill_descendant_processes(logger, pids_to_kill=None):
for descendant in descendant_processes:
logger.warn("Killing descendant process {} PID: {}"
.format(descendant.cmdline(), descendant.pid))
descendant.kill()
descendant.wait()
try:
descendant.kill()
descendant.wait()
except psutil.NoSuchProcess:
pass
logger.warn("Killed all descendant processes of {} PID: {}"
.format(this_process.cmdline(),
this_process.pid))
Expand Down

0 comments on commit f048e94

Please sign in to comment.