问题
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. Any fix for that?
回答1:
Async workers behave differently from sync workers:
- In sync workers, the worker will be blocked from fulfilling the request, so if a request takes longer than timeout, the worker will be killed and so will the request.
- In async workers, the worker is not blocked and stays responsive to fulfill other requests even when the request takes long. ie worker timeout and request timeout are different things in this case.
There is no request timeout parameter for uvicorn right now.
for more details: https://github.com/benoitc/gunicorn/issues/1493
来源:https://stackoverflow.com/questions/61061580/gunicorn-is-not-respecting-timeout-when-using-uvicornworker