Status 502: [WARNING] Invalid HTTP request received.

See original GitHub issue

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:

  • 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 = 300

Additional context

  • Added timeout in config after searching on the internet, did not work

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
gautamsinghania95commented, Nov 6, 2019

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.

3reactions
Saftophobiacommented, Apr 29, 2020

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"

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stuck with: WARNING: Invalid HTTP request received. #441
Hi there, I'm using FastAPI with uvicorn and I'm running into an issue which I'm not sure how to debug/solve. I wasn't sure...
Read more >
502 Bad Gateway - HTTP - MDN Web Docs
The HyperText Transfer Protocol (HTTP) 502 Bad Gateway server error response code indicates that the server, while acting as a gateway or proxy,...
Read more >
Invalid HTTP method in Traceback: Uvicorn - Stack Overflow
I was getting the same arcane WARNING: Invalid HTTP request received. error with an unhelpful stack trace. I tried all of the environment ......
Read more >
HTTP 502 status code (Bad Gateway) - Amazon CloudFront
An HTTP 502 status code (Bad Gateway) indicates that CloudFront wasn't able to serve the requested object because it couldn't connect to the...
Read more >
Understanding HTTP 502's - Skyhigh Security
This topic focuses on one of these status codes: HTTP 502. The 502 message is used by the Web Gateway to alert a...
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