Skip to content

Commit 3d39d76

Browse files
llama-router: async polling for process termination after SIGKILL
Poll process_running() at ROUTER_POLL_INTERVAL_MS until exit confirmed. Ensures VRAM freed before hot-swap. Update docs to use constant names
1 parent 109f11f commit 3d39d76

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tools/router/ARCHITECTURE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ This aligns with the project philosophy: **everything configurable at runtime, z
8585
3. If not running, or if a conflicting group is active:
8686
- Terminate conflicting backends
8787
- Spawn new llama-server with assigned port
88-
- Poll `/health` until ready (10s timeout)
88+
- Poll `/health` until ready (`ROUTER_BACKEND_READY_TIMEOUT_MS` timeout)
8989
4. Forward request to backend, streaming response back to client
9090
5. Backend remains running for subsequent requests
9191

9292
### Process Lifecycle
9393

9494
- **Spawn**: `fork()`/`CreateProcess()` with stdout/stderr capture
95-
- **Health polling**: 200ms intervals, 10s timeout
96-
- **Graceful shutdown**: SIGTERM → 1s wait → SIGKILL
95+
- **Health polling**: `ROUTER_BACKEND_HEALTH_POLL_MS` intervals, `ROUTER_BACKEND_READY_TIMEOUT_MS` timeout
96+
- **Graceful shutdown**: SIGTERM → wait `ROUTER_PROCESS_SHUTDOWN_TIMEOUT_MS` → SIGKILL → poll every `ROUTER_POLL_INTERVAL_MS` until exit
9797
- **Cleanup**: File descriptors closed, waitpid() called
9898

9999
---

tools/router/router-process.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ void terminate_process(ProcessHandle & handle) {
132132
if (!wait_for_process_exit(handle, ROUTER_PROCESS_SHUTDOWN_TIMEOUT_MS)) {
133133
LOG_ERR("Process pid=%d did not terminate, sending SIGKILL\n", static_cast<int>(handle.pid));
134134
kill(handle.pid, SIGKILL);
135-
wait_for_process_exit(handle, 1000);
135+
while (process_running(handle)) {
136+
std::this_thread::sleep_for(std::chrono::milliseconds(ROUTER_POLL_INTERVAL_MS));
137+
}
136138
}
137139
close_process(handle);
138140
#endif

0 commit comments

Comments
 (0)