aws / aws/bedrock-agentcore-sdk-python

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

オープン
#88 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
761
フォーク
147
平均マージ
1日 23時間
マージ済み PR(30日)
7

説明

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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

app.entrypoint 関数と、issue に示されている add_async_task、complete_async_task、app.run の呼び出しから始めます。デプロイされた環境で 15 分間のストリーミングタスクを再現し、ローカル実行と比較します。その際、ソケット警告がいつ表示されるかに注目してください。長時間実行されるタスクでデプロイされたストリームを引き続き利用できること、または runtime の制限とサポートされる処理方法が文書化されていることをもって完了とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
aws, python
領域
api, backend, cloud
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。