Gunicorn is not respecting timeout when using UvicornWorker

橙三吉。 提交于 2021-02-11 17:45:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!