Skip to content

Commit

Permalink
Fixes bug where processes are sent the wrong termination signal
Browse files Browse the repository at this point in the history
  • Loading branch information
djperrefort committed Oct 5, 2023
1 parent c7d5755 commit 65e79f0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions shinigami/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import asyncssh
import pandas as pd

INIT_PROCESS_ID = 1


def id_in_whitelist(id_value: int, whitelist: Collection[Union[int, Tuple[int, int]]]) -> bool:
"""Return whether an ID is in a list of ID values
Expand Down Expand Up @@ -84,7 +86,7 @@ async def terminate_errant_processes(
process_df = pd.read_fwf(StringIO(ps_return.stdout), widths=[11, 11, 11, 11, 500])

# Identify orphaned processes and filter them by the UID whitelist
orphaned = process_df[process_df.PPID == 1]
orphaned = process_df[process_df.PPID == INIT_PROCESS_ID]
terminate = orphaned[orphaned['UID'].apply(id_in_whitelist, whitelist=uid_whitelist)]
for _, row in terminate.iterrows():
logging.debug(f'[{node}] Marking for termination {dict(row)}')
Expand All @@ -93,6 +95,6 @@ async def terminate_errant_processes(
logging.info(f'[{node}] No orphans found')

elif not debug:
proc_id_str = ','.join(terminate.PGID.astype(str))
proc_id_str = ','.join(terminate.PGID.unique().astype(str))
logging.info(f"[{node}] Sending termination signal for process groups {proc_id_str}")
await conn.run(f"pkill --signal -9 --pgroup {proc_id_str}", check=True)
await conn.run(f"pkill --signal 9 --pgroup {proc_id_str}", check=True)

0 comments on commit 65e79f0

Please sign in to comment.