aws / aws/bedrock-agentcore-sdk-python

Long running task with streaming gets terminated with "WARNING:asyncio:socket.send() raised exception."

Abierto
#88 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
761
Forks
147
Merge medio
1 d 23 h
PR fusionados (30 d)
7

Descripción

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()
```

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza con la función app.entrypoint y las llamadas a add_async_task, complete_async_task y app.run mostradas en el issue. Reproduce la tarea de streaming de 15 minutos en el entorno desplegado y compárala con la ejecución local, centrándote en cuándo aparece la advertencia del socket. Se considera completado cuando el stream desplegado sigue siendo utilizable para la tarea de larga duración o se documentan la limitación del runtime y el manejo compatible.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
aws, python
Área
api, backend, cloud
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.