Add signal handling for graceful shutdown in server and improve clean…#597
Add signal handling for graceful shutdown in server and improve clean…#597helloyongyang merged 1 commit intomainfrom
Conversation
…up process in DistributedManager
Summary of ChangesHello @GACLove, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the stability and operational reliability of the LightX2V server, particularly in distributed setups. It introduces mechanisms for graceful shutdown upon receiving termination signals and refines the cleanup process for distributed resources, preventing potential resource leaks or unresponsive processes. Additionally, worker processes are made more resilient by intelligently handling master disconnection events, ensuring they can exit cleanly when the orchestrator is no longer available. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request introduces signal handling for graceful shutdown in the server and refines the cleanup process within the DistributedManager. Key improvements include the integration of the signal module, the use of a global _shutdown_requested flag, and a more robust cleanup method in DistributedManager that employs a timed thread for dist.destroy_process_group(). The broadcast_task_data and barrier methods now incorporate checks for the distributed environment's initialization and shutdown status, which significantly enhances system stability. Furthermore, the worker loop has been updated to specifically handle connection-related errors during shutdown, facilitating a more controlled and graceful exit.
| logger.info(f"Server rank {rank} received shutdown signal") | ||
| if inference_service: | ||
| inference_service.stop_distributed_inference() | ||
| os._exit(0) |
There was a problem hiding this comment.
The use of os._exit(0) in the signal handler is problematic for graceful shutdown. It bypasses normal Python interpreter shutdown procedures, including finally blocks and atexit handlers. This means that any cleanup logic in the finally block of run_server (e.g., inference_service.stop_distributed_inference()) will not be executed if a signal is received.
A more robust approach would be to set a flag in the signal handler and allow the main application loop to detect this flag and exit gracefully, ensuring all finally blocks and cleanup routines are executed. For example, the run_worker_loop could be designed to periodically check _shutdown_requested.
| if not dist.is_initialized(): | ||
| return | ||
|
|
||
| import threading |
#597) …up process in DistributedManager
…up process in DistributedManager