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

[Core] cleanup zmq ipc sockets on exit #11115

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

russellb
Copy link
Collaborator

I noticed that my dev machine had several hundred orphanied files from
old zmq ipc sockets that vllm didn't clean up.

This change uses atexit to ensure that these files are cleaned up.

I tested this using vllm serve with --tensor-parallel-size 4,
VLLM_USE_V1=1, and VLLM_ENABLE_V1_MULTIPROCESSING=1 to ensure that
all of these code paths were executed. I saw all sockets created and
cleaned up when I stopped vllm.

Signed-off-by: Russell Bryant [email protected]

Copy link

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

@mergify mergify bot added the frontend label Dec 11, 2024
Copy link
Collaborator

@robertgshaw2-neuralmagic robertgshaw2-neuralmagic left a comment

Choose a reason for hiding this comment

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

Nice, this atexit function is handy!

@github-actions github-actions bot added the ready ONLY add when PR is ready to merge/full CI is needed label Dec 11, 2024
@russellb
Copy link
Collaborator Author

Nice, this atexit function is handy!

It sure is, but it must be used with care when we're dealing with multiprocessing! I'm pretty sure a forked process will inherit atexit handlers that were registered prior to the fork. In most cases, I think there's more Pythonic cleanup (when objects are cleaned up), but for some things, when we really need something cleaned up, it's OK.

active_procs = [p for p in active_procs if p.is_alive()]
for p in active_procs:
p.kill()
self._cleanup_sockets()
Copy link
Collaborator

@tlrmchlsmth tlrmchlsmth Dec 11, 2024

Choose a reason for hiding this comment

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

Maybe we clean up the sockets before we terminate the workers, in case the client process gets impatient and sends a SIGKILL to this one while this process waits for the workers to gracefully terminate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cleaning up before terminating workers is more likely to fail because the workers may still have the socket open.

I think anywhere we use SIGKILL is giving up the illusion of proper cleanup. Hopefully that's rare?

Copy link

mergify bot commented Dec 11, 2024

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @russellb.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Dec 11, 2024
I noticed that my dev machine had several hundred orphanied files from
old zmq ipc sockets that vllm didn't clean up.

This change uses `atexit` to ensure that these files are cleaned up.

I tested this using `vllm serve` with `--tensor-parallel-size 4`,
`VLLM_USE_V1=1`, and `VLLM_ENABLE_V1_MULTIPROCESSING=1` to ensure that
all of these code paths were executed. I saw all sockets created and
cleaned up when I stopped vllm.

Signed-off-by: Russell Bryant <[email protected]>
auto-merge was automatically disabled December 12, 2024 00:17

Head branch was pushed to by a user without write access

@mergify mergify bot removed the needs-rebase label Dec 12, 2024
@russellb
Copy link
Collaborator Author

auto-merge was automatically disabled
Head branch was pushed to by a user without write access

@tlrmchlsmth you'll have to enable auto-merge again. I had to resolve some conflicts.

@ywang96 ywang96 merged commit ccede2b into vllm-project:main Dec 12, 2024
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants