Skip to content

Commit

Permalink
fix shutdown hang
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Blyschak <[email protected]>
  • Loading branch information
stepanblyschak committed Oct 17, 2024
1 parent a8c54ad commit ade9ec5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/system-health/health_checker/sysmonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ def task_worker(self):
logger.log_info("Start Listening to systemd bus (pid {0})".format(os.getpid()))
self.subscribe_sysbus()

def task_stop(self):
# FIXME: Gracefully stop `loop.run()`.
self._task_process.kill()
return True

def task_notify(self, msg):
if self.task_stopping_event.is_set():
return
Expand Down Expand Up @@ -478,9 +483,11 @@ def system_service(self):

from queue import Empty
# Queue to receive the STATEDB and Systemd state change event
while not self.task_stopping_event.is_set():
while True:
try:
msg = self.myQ.get(timeout=QUEUE_TIMEOUT)
if msg == "stop":
break
event = msg["unit"]
event_src = msg["evt_src"]
event_time = msg["time"]
Expand All @@ -500,26 +507,19 @@ def system_service(self):
monitor_statedb_table.task_stop()

def task_worker(self):
if self.task_stopping_event.is_set():
return
self.system_service()

def task_stop(self):
# Signal the process to stop
self.task_stopping_event.set()
self.myQ.put("stop")

# Wait for the process to exit
self._task_process.join(self._stop_timeout_secs)

# If the process didn't exit, attempt to kill it
if self._task_process.is_alive():
logger.log_notice("Attempting to kill sysmon main process with pid {}".format(self._task_process.pid))
os.kill(self._task_process.pid, signal.SIGKILL)

if self._task_process.is_alive():
logger.log_error("Sysmon main process with pid {} could not be killed".format(self._task_process.pid))
self._task_process.kill()
self._task_process.join()
return False

return True


0 comments on commit ade9ec5

Please sign in to comment.