Skip to content

fix: avoid chunked framing for bodiless aiohttp requests - #753

Open
jonathan343 wants to merge 1 commit into
developfrom
fix/aiohttp-bodiless-chunked-framing
Open

fix: avoid chunked framing for bodiless aiohttp requests#753
jonathan343 wants to merge 1 commit into
developfrom
fix/aiohttp-bodiless-chunked-framing

Conversation

@jonathan343

Copy link
Copy Markdown
Contributor

Summary

Fixes AIOHTTPClient requests that contain no payload but are transmitted as chunked streams.

This was observed with Amazon Polly’s DescribeVoices operation. The request reached the service, but Polly never returned response headers. The same operation completed normally when using AWSCRTHTTPClient.

Root cause

Smithy represents an omitted request payload as an empty AsyncBytesReader. Before this change, AIOHTTPClient passed that reader to aiohttp as request data.

Because aiohttp cannot determine the length of an arbitrary async iterable, it selected chunked transfer encoding:

# removed unrelated additional headers
GET /v1/voices?IncludeAdditionalLanguageCodes=false HTTP/1.1
Host: polly.us-east-1.amazonaws.com
Content-Type: application/octet-stream
Transfer-Encoding: chunked

Although an empty chunked request is permitted by HTTP, Polly did not return response headers for the observed request shape. The client consequently continued waiting until canceled or timed out.

The CRT transport does not produce this HTTP/1.1 chunked framing. Its HTTP/1.1 path omits an empty buffered body stream, while HTTP/2 does not use chunked transfer encoding.

Changes

AIOHTTPClient now distinguishes between an empty seekable body and a stream with data:

  • Empty seekable bodies are passed to aiohttp as None.
  • Nonempty bodies are restored to their original position before transmission.
  • Nonseekable bodies continue through the existing streaming path.
  • Requests with explicit Content-Length or Transfer-Encoding headers retain their existing framing behavior.
  • No request body is read or buffered to determine whether it is empty.

For a bodyless operation, aiohttp now emits an ordinary request without payload framing:

# removed unrelated additional headers
GET /v1/voices?IncludeAdditionalLanguageCodes=false HTTP/1.1
Host: polly.us-east-1.amazonaws.com

Verification

import asyncio

from aws_sdk_polly.client import PollyClient
from aws_sdk_polly.config import Config
from aws_sdk_polly.models import DescribeVoicesInput
from smithy_aws_core.identity import EnvironmentCredentialsResolver
from smithy_http.aio.aiohttp import AIOHTTPClient


async def main() -> None:
    config = Config(
        region="us-east-1",
        aws_credentials_identity_resolver=EnvironmentCredentialsResolver(),
        transport=AIOHTTPClient(),
    )
    client = PollyClient(config=config)

    response = await client.describe_voices(DescribeVoicesInput())
    print(f"Received {len(response.voices or [])} voices")

if __name__ == "__main__":
    asyncio.run(main())

Observed behavior:

  • Before: request stalls while waiting for response headers
  • After: Received 15 voices

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jonathan343
jonathan343 requested a review from a team as a code owner July 27, 2026 04:36

@Alan4506 Alan4506 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @jonathan343!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants