You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/12/02 18:51:20 UTC

[GitHub] [airflow] potiuk commented on a change in pull request #19935: Fix race condition when starting DagProcessorAgent

potiuk commented on a change in pull request #19935:
URL: https://github.com/apache/airflow/pull/19935#discussion_r761377814



##########
File path: airflow/utils/process_utils.py
##########
@@ -68,36 +73,51 @@ def on_terminate(p):
 
     def signal_procs(sig):
         try:
-            os.killpg(pgid, sig)
+            logger.info("Sending the signal %s to group %s", sig, process_group_id)
+            os.killpg(process_group_id, sig)
         except OSError as err:
             # If operation not permitted error is thrown due to run_as_user,
             # use sudo -n(--non-interactive) to kill the process
             if err.errno == errno.EPERM:
                 subprocess.check_call(
-                    ["sudo", "-n", "kill", "-" + str(int(sig))] + [str(p.pid) for p in children]
+                    ["sudo", "-n", "kill", "-" + str(int(sig))]
+                    + [str(p.pid) for p in all_processes_in_the_group]
                 )
+            elif err.errno == errno.ESRCH:
+                # There is a rare condition that the process has not managed yet to change it's process
+                # group. In this case os.killpg fails with ESRCH error
+                # So we additionally send a kill signal to the process itself.
+                logger.info(
+                    "Sending the signal %s to process %s as process group is missing.", sig, process_group_id
+                )
+                os.kill(process_group_id, sig)

Review comment:
       Good point!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org