Connection aborted after HttpParserInvalidMethodError when making consecutive POST requests
See original GitHub issueChecklist
- 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:
- Created 2 years ago
- Reactions:12
- Comments:11 (5 by maintainers)
Top GitHub Comments
Now resolved in 0.17.2 - https://github.com/encode/uvicorn/pull/1356
The solution I propose is to revert both. PRs were created:
Both memory leak and this issue are solved with my proposal.