Skip to content

Fix apptainer workspace cleanup: kill zombie child processes. - #2450

Merged
neubig merged 1 commit into
OpenHands:mainfrom
adityasoni9998:soni/apptainer_cleanup_fix
Mar 15, 2026
Merged

neubig merged 1 commit into
OpenHands:mainfrom
adityasoni9998:soni/apptainer_cleanup_fix

Conversation

@adityasoni9998

@adityasoni9998 adityasoni9998 commented Mar 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes the logic for cleaning up an Apptainer workspace instance. Currently self._process inherits the same process group as that of the parent process. As a result, when we cleanup and terminate this process here, the child processes spawned by the apptainer run command are not killed (for e.g. processes responsible for overlaying file-system) which causes them to become zombie processes.

This is particularly problematic for situations where the same machine spins up O(1K-10K) apptainer instances, for e.g. during rollouts for RL training. This PR fixes this issue by making two changes -

  • start self._process as a new session which ensures that self._process is the leader of its process group which also means that the PID of this process will also be the process group ID
  • during cleanup, instead of using process.terminate(), send an OS signal (SIGTERM/SIGKILL) through os.killpg(<PID of self._process == PID of this group>) to kill the entire process group including the child processes spawned by self._process.

Checklist

  • If the PR is changing/adding functionality, are there tests to reflect this?
  • If there is an example, have you run the example to make sure that it works?
  • If there are instructions on how to run the code, have you followed the instructions and made sure that it works?
  • If the feature is significant enough to require documentation, is there a PR open on the OpenHands/docs repository with the same branch name?
  • Is the github CI passing?

@neubig neubig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@neubig
neubig merged commit 737eae2 into OpenHands:main Mar 15, 2026
22 of 23 checks passed
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants