High severity intermediate · Fix: 5-10 min

ConnectionResetError

builtins.ConnectionResetError

What this error means
AWS Bedrock EventStream connection reset error occurs when the network connection is unexpectedly closed during streaming responses.

Stack trace

traceback
Traceback (most recent call last):
  File "app.py", line 42, in <module>
    response = client.invoke_model(...)
  File "/usr/local/lib/python3.9/site-packages/botocore/httpsession.py", line 263, in send
    raise ConnectionResetError("Connection reset by peer")
builtins.ConnectionResetError: Connection reset by peer
QUICK FIX
Add retry logic with exponential backoff around the Bedrock EventStream call to handle transient connection resets automatically.

Why it happens

This error happens because the TCP connection used for AWS Bedrock EventStream was unexpectedly closed by the server or network infrastructure. It can be caused by network instability, timeouts, or server-side throttling that forcibly closes the connection.

Detection

Monitor your application logs for ConnectionResetError exceptions during Bedrock streaming calls and track network latency or dropped packets to catch issues early.

Causes & fixes

1

Network instability or transient connectivity issues between client and AWS Bedrock endpoint

✓ Fix

Implement exponential backoff retries with jitter around the Bedrock streaming call to recover from transient network failures.

2

AWS Bedrock service throttling or limits causing the server to close the connection

✓ Fix

Check AWS CloudWatch metrics for throttling and increase client-side retry delays or request lower throughput to avoid hitting limits.

3

Client-side timeout settings too low causing premature connection closure

✓ Fix

Increase the HTTP client timeout settings in your AWS SDK or HTTP client configuration to allow longer streaming durations.

Code: broken vs fixed

Broken - triggers the error
python
import boto3

client = boto3.client('bedrock')

response = client.invoke_model(
    ModelId='my-model',
    Body=b'input data',
    ContentType='application/json'
)  # This line may raise ConnectionResetError
print(response)
Fixed - works correctly
python
import os
import time
import boto3
from botocore.exceptions import EndpointConnectionError

client = boto3.client('bedrock',
                      aws_access_key_id=os.environ['AWS_ACCESS_KEY_ID'],
                      aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
                      region_name=os.environ['AWS_REGION'])

max_retries = 5
for attempt in range(max_retries):
    try:
        response = client.invoke_model(
            ModelId='my-model',
            Body=b'input data',
            ContentType='application/json'
        )
        print(response)
        break
    except ConnectionResetError:
        if attempt == max_retries - 1:
            raise
        backoff = 2 ** attempt + (0.1 * attempt)
        time.sleep(backoff)  # Exponential backoff with jitter
        print(f'Retrying due to connection reset, attempt {attempt + 1}')
Added retry loop with exponential backoff to handle transient ConnectionResetError from AWS Bedrock EventStream calls.

Workaround

Wrap the Bedrock streaming call in try/except ConnectionResetError and on failure, re-establish the connection and retry the request after a short delay.

Prevention

Use robust retry policies with exponential backoff and monitor network health and AWS service limits to prevent connection resets during Bedrock streaming.

Python 3.9+ · boto3 >=1.26.0 · tested on 1.28.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.