-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server returns 400: "invalid character in chunk size header" for valid request #5220
Comments
Thanks for the reproducer. |
I suspect |
I've reprduced this issue with async def test_5220(aiohttp_client) -> None:
async def handler(request):
return web.Response(text="OK", status=200)
app = web.Application()
app.add_routes([web.get("/", handler)])
app.add_routes([web.put("/", handler)])
client = await aiohttp_client(app)
async def data_gen():
for _ in range(10):
yield b"just data"
await asyncio.sleep(0.1)
async with client.put("/", data=data_gen(), raise_for_status=True):
pass
async with client.get("/", raise_for_status=True):
pass ERROR aiohttp.server:web_protocol.py:425 Error handling request
Traceback (most recent call last):
File "/home/dmitry/Sources/aiohttp/aiohttp/web_protocol.py", line 345, in data_received
messages, upgraded, tail = self._request_parser.feed_data(data)
File "aiohttp/_http_parser.pyx", line 546, in aiohttp._http_parser.HttpParser.feed_data
raise ex
aiohttp.http_exceptions.BadHttpMessage: 400, message='invalid character in chunk size header' |
This is the packets dump dump.pcapng.gz |
This issue is really tricky. I'll try to explain what is happening! First of all
After sending this data client quits, but the connection is not closed, because according to HTTP 1.1 connections are On the server side, however, this wouldn't be an issue if So as you may have guessed, when client starts I've tried to fix this in #5238 |
@greshilov thanks for digging into the problem. I think the #5238 fixes the incorrect side. Reviewing the So, my plan is:
|
Ref: #5269. |
@asvetlov glad to hear! In addition to the new correct behaviour on server, shouldn't we protect aiohttp client users in such cases?
|
I think on both sides we should drop the connection even if keepalive is enabled but the payload was not fully read. The only difference is that on the server side halfclose-lingering-closing should be used. The client can just drop immediately. |
|
IMHO, if this issue is not easy to be fixed, then the workaround about |
I don't see how that's relevant... |
@Dreamsorcerer Sorry, I added the related post now. |
Still not sure how that's relevant. That is an issue with there actually being an invalid character in header (when read client-side), which is closed because we've enabled lenient options on the llhttp parser (though, currently may still be an issue if a response doesn't use CRLF for the line breaks: nodejs/llhttp#241). This is an issue about reading from a keep-alive connection that should have been closed (on the server-side). |
Thank you for your explanation. I agree with you now. It was me who confused these two issues. Should I delete my posts or just keep them here? |
Fixes #5220. I believe this is a better fix than #5238. That PR detects that we didn't finish sending a chunked response and then closes the connection. This PR ensures that we simply complete the chunked response by sending the EOF bytes, allowing the connection to remain open and be reused normally.
Fixes #5220. I believe this is a better fix than #5238. That PR detects that we didn't finish sending a chunked response and then closes the connection. This PR ensures that we simply complete the chunked response by sending the EOF bytes, allowing the connection to remain open and be reused normally. (cherry picked from commit 9c07121)
Fixes #5220. I believe this is a better fix than #5238. That PR detects that we didn't finish sending a chunked response and then closes the connection. This PR ensures that we simply complete the chunked response by sending the EOF bytes, allowing the connection to remain open and be reused normally. (cherry picked from commit 9c07121)
Fixes aio-libs#5220. I believe this is a better fix than aio-libs#5238. That PR detects that we didn't finish sending a chunked response and then closes the connection. This PR ensures that we simply complete the chunked response by sending the EOF bytes, allowing the connection to remain open and be reused normally. (cherry picked from commit 9c07121)
🐞 Describe the bug
When server ignores content of request with
Transfer-Encoding: chunked
, parsing of next request can fail.💡 To Reproduce
The following script:
Prints the following:
If I add
await request.content.read()
, the problem disappears.💡 Expected behavior
Server should not fail to parse valid request.
📋 Your version of the Python
📋 Your version of the aiohttp/yarl/multidict distributions
The text was updated successfully, but these errors were encountered: