-
-
Notifications
You must be signed in to change notification settings - Fork 328
fix: graceful shutdown instead of SIGKILL on worker processes #1349
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,9 +51,18 @@ def run_processes( | |
| ) | ||
|
|
||
| def terminating_signal_handler(_sig, _frame): | ||
| logger.info("Terminating server!!", bold=True) | ||
| logger.info("Gracefully shutting down server...", bold=True) | ||
| for process in process_pool: | ||
| process.kill() | ||
| process.terminate() | ||
|
|
||
| for process in process_pool: | ||
| process.join(timeout=30) | ||
| if process.is_alive(): | ||
| logger.warning("Process %s did not shut down in time, forcing kill.", process.pid) | ||
| process.kill() | ||
| process.join(timeout=5) | ||
|
|
||
| sys.exit(0) | ||
|
|
||
| signal.signal(signal.SIGINT, terminating_signal_handler) | ||
| signal.signal(signal.SIGTERM, terminating_signal_handler) | ||
|
|
@@ -220,6 +229,12 @@ def spawn_process( | |
| try: | ||
| server.start(socket, workers) | ||
| loop = asyncio.get_event_loop() | ||
|
|
||
| if not sys.platform.startswith("win32"): | ||
| loop.add_signal_handler(signal.SIGTERM, loop.stop) | ||
|
|
||
| loop.run_forever() | ||
| except KeyboardInterrupt: | ||
| pass | ||
| finally: | ||
| loop.close() | ||
|
Comment on lines
+233
to
240
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect whether workers have explicit SIGINT handling or process-group isolation.
rg -n -C2 'signal\.SIGINT|signal\.signal\(signal\.SIGINT|add_signal_handler\(signal\.SIGINT|start_new_session|setsid|setpgrp' .Repository: sparckles/Robyn Length of output: 1664 🏁 Script executed: # First, let's see the overall structure of processpool.py
head -100 robyn/processpool.py | cat -nRepository: sparckles/Robyn Length of output: 3620 🏁 Script executed: # Continue reading to see spawn_process and worker implementation
sed -n '100,250p' robyn/processpool.py | cat -nRepository: sparckles/Robyn Length of output: 5761 Workers can still bypass graceful shutdown on Ctrl+C. Only 🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolve — reviewed, signal handling is correct for the current architecture. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rate Limit Exceeded
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,7 +123,13 @@ def __init__(self, file_path: str, directory_path: str) -> None: | |
|
|
||
| def stop_server(self) -> None: | ||
| if self.process: | ||
| os.kill(self.process.pid, signal.SIGTERM) # Stop the subprocess using os.kill() | ||
| self.process.terminate() | ||
| try: | ||
| self.process.wait(timeout=5) | ||
| except subprocess.TimeoutExpired: | ||
| logger.warning("Process %s did not shut down in time, forcing kill.", self.process.pid) | ||
| self.process.kill() | ||
| self.process.wait() | ||
|
Comment on lines
+126
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Read-only verification: inspect kill/wait sequencing in shutdown paths.
rg -nP --type=py -C4 '\.terminate\(\)|\.kill\(\)|\.wait\(' robyn/reloader.py robyn/processpool.pyRepository: sparckles/Robyn Length of output: 2282 Add a timeout to the post-kill wait to prevent indefinite blocking during reload. Line 132 calls Proposed fix except subprocess.TimeoutExpired:
logger.warning("Process %s did not shut down in time, forcing kill.", self.process.pid)
self.process.kill()
- self.process.wait()
+ try:
+ self.process.wait(timeout=5)
+ except subprocess.TimeoutExpired:
+ logger.error("Process %s did not exit after force kill.", self.process.pid)🤖 Prompt for AI Agents
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolve — out of scope. Reloader improvements tracked separately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rate Limit Exceeded
|
||
|
|
||
| def reload(self) -> None: | ||
| self.stop_server() | ||
|
|
@@ -138,10 +144,6 @@ def reload(self) -> None: | |
| clean_rust_binaries(self.built_rust_binaries) | ||
| self.built_rust_binaries = compile_rust_files(self.directory_path) | ||
|
|
||
| prev_process = self.process | ||
| if prev_process: | ||
| prev_process.kill() | ||
|
|
||
| self.process = subprocess.Popen( | ||
| [sys.executable, *arguments], | ||
| env=new_env, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.