Skip to content

fix: avoid shutdown hang on warmup thread#19008

Open
kuafou wants to merge 1 commit intosgl-project:mainfrom
kuafou:fix/http-server-hang
Open

fix: avoid shutdown hang on warmup thread#19008
kuafou wants to merge 1 commit intosgl-project:mainfrom
kuafou:fix/http-server-hang

Conversation

@kuafou
Copy link
Contributor

@kuafou kuafou commented Feb 19, 2026

Motivation

When uvicorn fails to bind (e.g., the port is already in use),
the HTTP server process hangs for around 120 seconds before exiting.

The reason is:

  1. The warmup thread keeps polling /model_info and may run for up to 120s.
  2. In the FastAPI lifespan handler, the finally block calls
    warmup_thread.join(), which blocks indefinitely while waiting for the thread.
  3. After uvicorn.run() returns, Python’s internal threading._shutdown()
    also waits for non-daemon threads, causing another blocking point.

As a result, the process appears stuck instead of exiting promptly.

Modifications

  • Set daemon=True when creating the warmup thread so interpreter shutdown does not wait for it.
  • Change the explicit join in lifespan to use a timeout: warmup_thread.join(timeout=5.0)

This prevents indefinite blocking during shutdown and allows the process to exit quickly if startup fails.

Notes

  • grpc_server.py already contains similar explicit cleanup logic.
  • This change only affects shutdown behavior when the server fails to start.
  • Normal warmup and serving flow are unchanged.

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kuafou, 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 resolves a critical server shutdown issue that occurred when the HTTP server failed to start, such as due to a port conflict. The changes ensure that the server process exits promptly instead of appearing stuck, by improving the handling of the warmup thread's lifecycle and its interaction with the application's shutdown sequence.

Highlights

  • Shutdown Hang Fix: Addressed an issue where the HTTP server process would hang for an extended period (up to 120 seconds) during shutdown if uvicorn failed to bind, by preventing indefinite blocking of the warmup thread.
  • Warmup Thread Management: Configured the warmup thread as a daemon to ensure it does not block Python's internal threading._shutdown() and added a 5-second timeout to warmup_thread.join() in the FastAPI lifespan handler.
  • API Response Simplification: Removed the 'weight_version' field from the /model_info endpoint's response.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • python/sglang/srt/entrypoints/http_server.py
    • Set the warmup_thread as a daemon thread.
    • Added a timeout=5.0 argument to warmup_thread.join() in the lifespan function.
    • Removed the weight_version key from the dictionary returned by the model_info endpoint.
    • Converted an f-string in a logger.info call to a regular string.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively resolves a server shutdown hang that occurs when the uvicorn server fails to start. The approach of setting the warmup thread as a daemon and using a timed join is correct and well-implemented. The changes are clear and directly address the issue. I have one minor suggestion to improve maintainability by replacing a magic number with a named constant.

@kuafou kuafou changed the title fix: void shutdown hang on warmup thread fix: avoid shutdown hang on warmup thread Feb 19, 2026
@kuafou
Copy link
Contributor Author

kuafou commented Feb 19, 2026

/tag-run-ci-label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments