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.

Connection aborted after HttpParserInvalidMethodError when making consecutive POST requests

See original GitHub issue

Checklist

  • The bug is reproducible against the latest release or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

After making a few POST requests, one of the requests ends with the connection aborted. The server logs a log about an invalid HTTP method, however only POST method is consistently attempted.

Steps to reproduce the bug

The bug is reproduced when making multiple requests.posts against a service running with latest uvicorn

Unfortunately I was not able to create a reliable reproduction, as running locally I seemed to make successful requests

Expected behavior

All the requests used to pass in sequence without errors

Actual behavior

One of the requests, after an inconsistent number of successful requests, fails with a connection error after sending the request. The server logs

Debugging material

Request aborted

  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 117, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 501, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

Server warning (uvicorn.error).

"Invalid HTTP request received."
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 132, in data_received
    self.parser.feed_data(data)
  File "httptools/parser/parser.pyx", line 212, in httptools.parser.parser.HttpParser.feed_data
httptools.parser.errors.HttpParserInvalidMethodError: Invalid method encountered

Environment

  • Running uvicorn 0.17.1 with CPython 3.10.1 on Linux
  • Encountered with Kubernetes services, without reverse proxy/ingress

Additional context

Since requests library is using a keepalive for the requests, a suspect change is the recent https://github.com/encode/uvicorn/pull/1332, and reverting uvicorn version seems to make the problem go away.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:12
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tomchristiecommented, Feb 3, 2022
1reaction
Kludexcommented, Feb 3, 2022

The solution I propose is to revert both. PRs were created:

Both memory leak and this issue are solved with my proposal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection aborted requests error - python - Stack Overflow
Basically what I've done is I took all your variables and put them in the top of your code and made them global...
Read more >
Send multiple http post request to the same server consecutively
I am able to make http post requests to all of them individually and ... post requests one after and another and then...
Read more >
Connection Error - POST request : Forums - PythonAnywhere
I am trying to send data from an outside computer via a POST request. I get the following error ... ConnectionError: ('Connection aborted....
Read more >
HTTP Methods GET vs POST - W3Schools
GET requests are only used to request data (not modify). The POST Method. POST is used to send data to a server to...
Read more >
HTTP Request Methods – Get vs Put vs Post Explained with ...
These resources are made available to us via an API and we make requests to these APIs via the HTTP protocol. API stands...
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