question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Gunicorn with UvicornWorker is not respecting the timeout

See original GitHub issue

I am setting up a timeout check so I made and endpoint:

@app.get("/tc", status_code=200)
def timeout_check():
    time.sleep(500)
    return "NOT OK"

I am using the docker image tiangolo/uvicorn-gunicorn-fastapi:python3.7 and my command to run the server:

CMD ["gunicorn","--log-level","debug","--keep-alive","15", "--reload", "-b", "0.0.0.0:8080", "--timeout", "15", "--worker-class=uvicorn.workers.UvicornH11Worker", "--workers=10", "myapp.main:app"]

I am expecting the endpoint to fail after 15 seconds, but it doesn’t. Seems like the timeout is not respected.

Is there any mistake in my configuration?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
euri10commented, Apr 7, 2020
0reactions
assem-chcommented, Mar 25, 2021

I end up with this solution:

class RequestKillerWorker(UvicornWorker):
  
    def notify(self):
        if not self.server.server_state.tasks:
            self.tmp.notify()

so basically the worker is killed only if busy after the timeout

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gunicorn is not respecting timeout when using UvicornWorker
I am expecting the endpoint to fail after 15 seconds, but it doesn't. Seems like the timeout is not respected. Any fix for...
Read more >
How to resolve the gunicorn critical worker timeout error?
I have to restart the gunicorn process to bring up website. Following is the error log : 2014-02-16 14:29:53 [1267] [CRITICAL] WORKER TIMEOUT...
Read more >
Deployment - Uvicorn
Run uvicorn --reload from the command line for local development. Run gunicorn -k uvicorn.workers.UvicornWorker for production. Additionally run behind Nginx ...
Read more >
tiangolo/uvicorn-gunicorn-fastapi - Docker Image
Notice that Uvicorn and ASGI frameworks like FastAPI are async, not sync. So it's probably safe to have higher timeouts than for sync...
Read more >
tiangolo/fastapi - Gitter
@andyfaizan You should be able to change gunicorn timeout settings by ... the following command -> https://github.com/tiangolo/uvicorn-gunicorn-docker/blob/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found