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.

Stuck with: WARNING: Invalid HTTP request received.

See original GitHub issue

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 where to post this, but since the error message comes from uvicorn I decided to post it here.

There is no issue if I send a single GET request:

DEBUG: ('10.144.0.115', 48348) - Connected
DEBUG: ('10.144.0.115', 48348) - ASGI [48] Started
DEBUG: ('10.144.0.115', 48348) - ASGI [48] Received {'type': 'http.response.start', 'status': 200, 'headers': '<...>'}
INFO: ('10.144.0.115', 48348) - "GET /charts HTTP/1.1" 200
DEBUG: ('10.144.0.115', 48348) - ASGI [48] Received {'type': 'http.response.body', 'body': '<41112 bytes>'}
DEBUG: ('10.144.0.115', 48348) - ASGI [48] Completed
DEBUG: ('10.144.0.115', 48348) - Disconnected

But if I send a second GET request while the connection from the first request is still open I get WARNING: Invalid HTTP request received.. Here is the complete log for the two requests:

DEBUG: ('10.144.0.115', 49422) - Connected
DEBUG: ('10.144.0.115', 49422) - ASGI [51] Started
DEBUG: ('10.144.0.115', 49422) - ASGI [51] Received {'type': 'http.response.start', 'status': 200, 'headers': '<...>'}
INFO: ('10.144.0.115', 49422) - "GET /charts HTTP/1.1" 200
DEBUG: ('10.144.0.115', 49422) - ASGI [51] Received {'type': 'http.response.body', 'body': '<41112 bytes>'}
DEBUG: ('10.144.0.115', 49422) - ASGI [51] Completed
WARNING: Invalid HTTP request received.
DEBUG: ('10.144.0.115', 49422) - Disconnected
DEBUG: ('10.144.0.115', 49430) - Connected
DEBUG: ('10.144.0.115', 49430) - ASGI [52] Started
DEBUG: ('10.144.0.115', 49430) - ASGI [52] Received {'type': 'http.response.start', 'status': 200, 'headers': '<...>'}
INFO: ('10.144.0.115', 49430) - "GET /charts HTTP/1.1" 200
DEBUG: ('10.144.0.115', 49430) - ASGI [52] Received {'type': 'http.response.body', 'body': '<41112 bytes>'}
DEBUG: ('10.144.0.115', 49430) - ASGI [52] Completed
DEBUG: ('10.144.0.115', 49430) - Disconnected

This isn’t too bad, because I still receive the responses for each request, even with the warning.

But if I try to send a POST request from a react-frontend it gets worse. The POST request from the frontend comes with a Preflight OPTIONS request. That means if I hit the send-button in the frontend the browser sends an OPTIONS request immediately followed by a POST request.

The server log looks like this:

DEBUG: ('10.144.0.115', 44982) - Connected
DEBUG: ('10.144.0.115', 44982) - ASGI [14] Started
DEBUG: ('10.144.0.115', 44982) - ASGI [14] Received {'type': 'http.response.start', 'status': 200, 'headers': '<...>'}
INFO: ('10.144.0.115', 44982) - "OPTIONS /colors HTTP/1.1" 200
DEBUG: ('10.144.0.115', 44982) - ASGI [14] Received {'type': 'http.response.body', 'body': '<2 bytes>'}
DEBUG: ('10.144.0.115', 44982) - ASGI [14] Completed
WARNING: Invalid HTTP request received.
DEBUG: ('10.144.0.115', 44982) - Disconnected

The OPTIONS request gets through, but the POST request doesn’t. The payload from the frontend doesn’t reach the backend.

Now the strangest thing: If I hammer the send-button multiple times a second, the POST request will get through eventually.

Does anyone know what’s going on or how this could be solved?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
reminizdevelopercommented, Dec 2, 2019

Hi there, I do have the same issue but I can’t replicate it locally, I only see it on a deployed kubernetes cluster.

I am using gunicorn and the issue disappear if I switch from uvicorn.workers.UvicornWorker to uvicorn.workers.UvicornH11Worker.

It seems related to #344

2reactions
jlienSagecommented, Apr 27, 2020

@euri10 Just rebuilt our image using latest base image. Uvicorn is 0.11.3 and gunicorn is 20.0.4.

The issue persists when we turn on CORS and Azure inserts its middleware to handle CORS.

Update: @euri10 Adding the following environment variable is a work-around for this issue: GUNICORN_CMD_ARGS="--keep-alive 0"

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
WARNING: Invalid HTTP request received. Only when running ...
I am trying to write an Excel addin that uses node.js to make a GET request to a fastapi/uvicorn server on localhost.
Read more >
Troubleshooting Amazon OpenSearch Service
If you receive an Invalid Host Header error when making a request, check that your client or proxy includes the OpenSearch Service domain...
Read more >
Invalid Http Method In Traceback: Uvicorn - ADocLib
Invalid HTTP method in Traceback: Uvicorn. I was getting the same arcane WARNING: Invalid HTTP request received. error with an unhelpful stack trace....
Read more >
HAProxy version 2.2.22 - Configuration Manual - GitHub Pages
First, let's consider this HTTP request : Line Contents number 1 GET ... In such cases, a warning message will be emitted during...
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