Skip to content

read_timeout in HTTPRequestConfiguration is never applied #790

Description

@iwamot

HTTPRequestConfiguration.read_timeout has no effect. A client configured with http_request_config=HTTPRequestConfiguration(read_timeout=1) keeps waiting on a server that sends nothing.

Versions

  • smithy-core 0.8.1
  • smithy-http 0.5.0
  • smithy-aws-core 0.11.0
  • aws-sdk-bedrock-agentcore 0.11.0
  • aiohttp 3.14.3
  • CPython 3.12.7 on Linux

Reproduction

The server below accepts the request and then sends nothing for 3 seconds, while the client is configured with read_timeout=1. No AWS account is needed.

"""read_timeout is not enforced: the server stalls for 3s, read_timeout is 1s."""

import asyncio
import threading
import time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer

from aws_sdk_bedrock_agentcore.client import AsyncBedrockAgentCoreClient
from aws_sdk_bedrock_agentcore.config import AsyncBedrockAgentCoreConfig
from aws_sdk_bedrock_agentcore.models import InvokeAgentRuntimeInput
from smithy_aws_core.identity import AWSCredentialsIdentity, StaticCredentialsResolver
from smithy_http.interfaces import HTTPRequestConfiguration

STALL = 3.0
READ_TIMEOUT = 1.0


class Handler(BaseHTTPRequestHandler):
    protocol_version = "HTTP/1.1"

    def log_message(self, *args):
        pass

    def do_POST(self):
        self.rfile.read(int(self.headers.get("Content-Length", 0)))
        time.sleep(STALL)  # send nothing at all for 3 seconds
        body = b'{"ok": true}'
        self.send_response(200)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        self.wfile.write(body)


async def main() -> None:
    server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
    threading.Thread(target=server.serve_forever, daemon=True).start()

    config = await AsyncBedrockAgentCoreConfig.resolve(
        region="us-west-2",
        endpoint_uri=f"http://127.0.0.1:{server.server_address[1]}",
        aws_credentials_identity_resolver=StaticCredentialsResolver(
            identity=AWSCredentialsIdentity(
                access_key_id="AKIAIOSFODNN7EXAMPLE",
                secret_access_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
            )
        ),
        http_request_config=HTTPRequestConfiguration(read_timeout=READ_TIMEOUT),
    )
    client = AsyncBedrockAgentCoreClient(config=config)

    start = time.monotonic()
    try:
        await client.invoke_agent_runtime(
            InvokeAgentRuntimeInput(
                agent_runtime_arn="arn:aws:bedrock-agentcore:us-west-2:123456789012:runtime/example-abc123",
                runtime_session_id="s" * 40,
                content_type="application/json",
                payload=b"{}",
            )
        )
    except Exception as error:
        print(f"raised after {time.monotonic() - start:.2f}s: {type(error).__name__}")
    else:
        print(f"returned after {time.monotonic() - start:.2f}s with no timeout error")

    server.shutdown()


asyncio.run(main())

Output:

returned after 3.02s with no timeout error

I'd expect this to fail after about 1 second.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions