aws / aws/bedrock-agentcore-sdk-python
Long running task with streaming gets terminated with "WARNING:asyncio:socket.send() raised exception."
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 764
- Forks
- 148
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 7
Description
I'm trying to execute some long running task, but every time when it reaches 6 min or 8 min duration it automatically cuts of connection and shows "WARNING:asyncio:socket.send() raised exception." in logs. I tried in locally its working fine, but on deployed version this is happening, I'm using "app.add_async_task()" as well as "app.complete_async_task()", they are getting triggered and its showing in logs, but in between after 6 min or 8 min it starts showing that error. My code looks something like this:
import os
import asyncio
from datetime import datetime
from strands import Agent, tool
from strands.models import OpenAIModel
from bedrock_agentcore import BedrockAgentCoreApp
@tool
async def background_task(minutes: int = 15) -> str:
for i in range(minutes):
await asyncio.sleep(60)
return f"Background task completed in ~{minutes} minutes."
model = OpenAIModel(
client_args={"api_key": os.getenv("OPENAI_API_KEY")},
model_id="gpt-5-mini",
reasoning={"effort": "medium"},
text={"verbosity": "low"},
)
agent = Agent(
model=model,
tools=[background_task],
instructions="Call the `background_task` tool for 15 minutes to simulate a long job."
)
app = BedrockAgentCoreApp()
@app.entrypoint
async def agent_invocation(payload):
task_id = None
user_message = payload.get("prompt", "No prompt found in input")
user_message += "\n\nUse background_task for 15 minutes."
stream = agent.stream_async(user_message)
task_id = app.add_async_task("Agent_stream")
try:
async for event in stream:
print(event)
yield event
finally:
if task_id:
app.complete_async_task(task_id)
if __name__ == "__main__":
app.run()
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the app.entrypoint function and the add_async_task, complete_async_task, and app.run calls shown in the issue. Reproduce the 15-minute streaming task in the deployed environment and compare it with the local run, focusing on when the socket warning appears. Done means the deployed stream remains usable for the long-running task or the runtime limitation and supported handling are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100