SIGTERM cancels in-flight requests and the server always ends by SIGKILL
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Start with shutdown_event_loop and the signal lambda in gpustack/utils/process.py, then handle_termination_signal and its self-call to terminate_process_tree(os.getpid()). The lifespan shutdown in server/app.py shows what must run before exit. Done means in-flight requests finish during a SIGTERM drain, the process exits without SIGKILL, and tests in tests/utils cover both handlers. The author has a ready fix and an open question about the timeout env var, so confirm with a maintainer before starting.
Written by the indexing model from the issue text.
Description
On SIGTERM or Ctrl+C, shutdown_event_loop in gpustack/utils/process.py cancels every task in the loop, uvicorn's serve() and the request tasks included. Then terminate_process_tree(os.getpid()) sends SIGTERM to its own process, waits 3 s on its own pid and SIGKILLs it. uvicorn catches the same signal and would drain by itself, but the cancel gets there first.
I ran a server built from main (189a43a) with python -m gpustack.main start, PostgreSQL 17 and --gateway-mode disabled. A POST /v2/model-providers/test-model against a provider that answers after 4 s was in flight when SIGTERM arrived. It got HTTP 500 after 1.2 s, an open GET /v2/models?watch=true was cut at once, the app lifespan shutdown (the aiohttp sessions in server/app.py) never ran, and the process was SIGKILLed 3.4 s after SIGTERM. That happens on every stop. A worker registered to that server was SIGKILLed 6.1 s after SIGTERM with a lifespan CancelledError. The two CancelledError tracebacks followed by Killed in the verification log on #3026, and the ones in #5087, look like this.
Two smaller things in the same file. The loop handler's lambda doesn't bind sig, so Ctrl+C is logged as signal 15. And the sync handle_termination_signal that the serving, provisioning and benchmark children install has the same self-kill, so every child stop takes 3 s and ends with -9.
From the history it doesn't look intended: bb225f00 ("fix: graceful exit") ended with sys.exit(0), and faeb0cc7 three days later switched to terminate_process_tree(os.getpid()), reusing the helper for child trees on its own pid.
I have a fix ready. On a signal it sets should_exit on the uvicorn servers and waits for serve() to return before cancelling the other tasks, and it ends with os._exit(128 + sig) instead of signalling itself, so a terminated provisioning child still exits non-zero. With it the same request gets HTTP 200 after 4.0 s, the lifespan shutdown runs and the server exits with 143. Tests in tests/utils cover both handlers and fail on main.
The drain needs a bound, because watch streams never end by themselves. I used uvicorn's timeout_graceful_shutdown from a new GPUSTACK_GRACEFUL_SHUTDOWN_TIMEOUT, 5 s by default. Is an env var the way you'd want that configured, and should I open the PR?
- Dominant language
- Python
- Stars
- 6.1k
- Forks
- 750
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 109
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from gpustack/gpustack
-
ui
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
Change log level of kubernetes.client.rest response body log to TRACEPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
gpustack/gpustack#6844 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
gpustack/gpustack#6834 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Password policy has no minimum length — a 4-character password passes validationPossibly taken @Tkrechet claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
All issues in gpustack/gpustack
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
software-mansion-labs/Diplomat#20 ·
Maintainers usually reply within 1 day
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaPossibly taken @lijy91 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
libnativeapi/nativeapi#53 · 1 reaction ·
Maintainers usually reply within 1 day
-
View Counts discarded due to field name mismatchPossibly taken @rsiva0400 claimed this today. Opensite-bug triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Model version publishes the new UK firm entity as a personPossibly taken @vahid-ahmadi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
PolicyEngine/policyengine.py#764 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
spcl/HPCAgent-Bench#264 ·
Maintainers usually reply within 1 day