Cancel monitor and server tasks on backend shutdown#669
Open
Fiona-Waters wants to merge 1 commit intoOpenPipe:mainfrom
Open
Cancel monitor and server tasks on backend shutdown#669Fiona-Waters wants to merge 1 commit intoOpenPipe:mainfrom
Fiona-Waters wants to merge 1 commit intoOpenPipe:mainfrom
Conversation
Two fire-and-forget asyncio tasks were never cancelled during shutdown: 1. `_monitor_openai_server` in `LocalBackend` — polls vLLM health every 30s. After 3 consecutive ConnectionRefusedError failures (because vLLM is already gone), it re-raises, producing "Task exception was never retrieved" and a non-zero process exit. 2. `openai_server_task` in `UnslothService` (shared mode) — the uvicorn server task, also orphaned on shutdown. In containerized environments (Kubeflow, KubeRay), the non-zero exit causes pod restarts even though training completed successfully. Fix: store both task references and cancel them during close()/aclose(). Iterate over list() copies to avoid RuntimeError from dict mutation when done_callbacks fire during await. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_monitor_openai_servertask references inLocalBackendand cancel them duringclose()/_close()openai_server_taskreference inUnslothServiceand cancel it duringaclose()/close()list()copies to avoidRuntimeErrorfrom dict mutation when done_callbacks fire during awaitclose()cancels monitor tasksFixes ##668
Test plan
test_local_backend_monitor.pytest passestest_close_cancels_monitor_taskstest passesLocalBackendtraining in shared mode inside a container — pod should exit cleanly after training completesCo-Authored-By: Claude Opus 4.6 noreply@anthropic.com