I was trying to build a typeahead search API. This API gets called in quick succession, and I am getting an intermittent 502 response.
To Reproduce
Not sure how to reproduce this, as normal API calls, when spaced out, are working fine.
Expected behavior - Logs
2019-11-05T06:17:55.447961016Z [2019-11-05 06:17:55 +0000] [16] [INFO] ('100.96.0.56', 50964) - "POST <<URL_NAME>> HTTP/1.1" 200
Noted Intermittent Behaviour - Logs
2019-11-05T06:17:56.459601437Z [2019-11-05 06:17:56 +0000] [16] [WARNING] Invalid HTTP request received.
Environment:
bind = "0.0.0.0:4000"
workers = 2
worker_class = "uvicorn.workers.UvicornWorker"
timeout = 300
Additional context
Not sure how to help without a minimum example, maybe you can try to hit
your endpoint with ab or wrk and get reproducibility?
Le mar. 5 nov. 2019 Ã 7:25 AM, gautamsinghania95 notifications@github.com
a écrit :
I was trying to build a typeahead search API. This API gets called in
quick succession, and I am getting an intermittent 502 response.To Reproduce
Not sure how to reproduce this, as normal API calls, when spaced out, are
working fine.Expected behavior - Logs
2019-11-05T06:17:55.447961016Z [2019-11-05 06:17:55 +0000] [16] [INFO] ('100.96.0.56', 50964) - "POST <
> HTTP/1.1" 200 Noted Intermittent Behaviour - Logs
2019-11-05T06:17:56.459601437Z [2019-11-05 06:17:56 +0000] [16] [WARNING] Invalid HTTP request received.
Environment:
- OS: Debian GNU/Linux 10 (buster)
- FastAPI Version : 0.38.1
- Python version: 3.6
- Server: Gunicorn with 2 Uvicorn workers (see config file below)
bind = "0.0.0.0:4000"
workers = 2
worker_class = "uvicorn.workers.UvicornWorker"
timeout = 300Additional context
- Added timeout in config after searching on the internet, did not work
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/tiangolo/fastapi/issues/680?email_source=notifications&email_token=AAINSPUEFVDANXRABQ2TEODQSEGWJA5CNFSM4JI6FYKKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HWZQLVA,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAINSPVFFABQU2ZPFAQ77KTQSEGWJANCNFSM4JI6FYKA
.
Hi!!
This is an issue with the deployed version of the app. I have tried to reproduce the problem in my local environment, but to no effect.
Please see if you can help in some other fashion.
Thanks!
Gautam
Hi,
Closing the issue as it was resolved from my end.
Resolution: The deployment platform only accepted HTTP 1.1 calls, but the uvicorn worker class I was using uvicorn.workers.UvicornWorker was sending both types of request. Replacing it with uvicorn.workers.UvicornH11Worker resolved it.
Thanks.
glad you solved it, for reference which plateform is it and by both types of request you mean 1.0 and 1.1 calls ?
Thanks for the help here @euri10 ! :clap: :bow:
Thanks for reporting back and closing the issue @gautamsinghania95 :+1:
@gautamsinghania95 sorry but can you give more information on how to do that? I have the same issue as you and can't seem to find how to change uvicorn.workers.UvicornWorker
Thanks in advance
edit: nevermind, I found it
it's the http parameter that you put as "h11"
According to https://github.com/tiangolo/uvicorn-gunicorn-docker/pull/38, you can set it as an environment variable now WORKER_CLASS="uvicorn.workers.UvicornH11Worker"
Most helpful comment
Hi,
Closing the issue as it was resolved from my end.
Resolution: The deployment platform only accepted HTTP 1.1 calls, but the uvicorn worker class I was using
uvicorn.workers.UvicornWorkerwas sending both types of request. Replacing it withuvicorn.workers.UvicornH11Workerresolved it.Thanks.