Skip to content
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

Add workers graceful timeout - test refactor #459

Conversation

hendrikmuhs
Copy link
Contributor

Follow-up from #435, just to demonstrate a possible refactoring

Granian uses multiprocessiong to keep track of workers. On respawn and stop it uses SIGTERM together with join without a timeout(although timeout is exposed). If a worker refuses to gracefully stop, the granian main loop can get stuck at the join

This change implements a timeout for graceful stopping of workers with a default of 30s. If the timeout is breached the worker gets force stopped using SIGKILL. The timeout can be changed with --workers-graceful-timeout on the cmdline or as parameter in an app.

Related work: gunicorn

Reproduction: The issue can be simulated by starting a thread in a worker without daemonizing it: threading.Thread(target=slow_thread).start(). If granian is used together with FastAPI it also works with a background task: background_tasks.add_task(slow_task). Note: The thread or task doesn't have to be hanging, but just has to be running at the time granian tries to stop the worker.

@hendrikmuhs hendrikmuhs closed this Dec 9, 2024
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