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

Fix job cleanup on agents #355

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions lnst/Agent/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,12 @@ def kill_job(self, job_id, signal):

def kill_jobs(self):
logging.info("Killing all forked processes.")
self._job_context.cleanup()
self._job_context.kill_all_jobs()
return "Commands killed"

def machine_cleanup(self):
logging.info("Performing machine cleanup.")
self._job_context.cleanup()
self._job_context.kill_all_jobs()

self.restore_system_config()

Expand Down Expand Up @@ -1061,14 +1061,12 @@ def _process_msg(self, msg):
self._job_context.del_cmd(job)
self._server_handler.send_data_to_ctl(msg)
elif msg["type"] == "job_finished":
job = self._job_context.get_job(msg["job_id"])
job = self._job_context.pop_job(msg["job_id"])
job.join()

job.set_finished(msg["result"])
self._server_handler.send_data_to_ctl(msg)

self._job_context.del_job(job)

elif msg["type"] == "from_netns":
msg["data"]["netns"] = msg["netns"]
self._server_handler.send_data_to_ctl(msg["data"])
Expand Down
11 changes: 5 additions & 6 deletions lnst/Agent/Job.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ def get_job(self, id):
else:
return None

def _kill_all_jobs(self):
def pop_job(self, id: int) -> "Job":
return self._dict.pop(id)

def kill_all_jobs(self) -> None:
logging.debug("Killing all jobs")
for id in self._dict:
if not self._dict[id]._finished:
self._dict[id].kill(sig=signal.SIGKILL)

def cleanup(self):
logging.debug("Cleaning up leftover processes.")
self._kill_all_jobs()
self._dict = {}

def get_parent_pipes(self):
pipes = {}
for key in self._dict:
Expand Down
Loading