Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[healthd] fix healthd shutdown race #19504

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 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,28 +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()
#Clear the resources of mpmgr- Queue
self.mpmgr.shutdown()
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


Loading