mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-21 05:14:45 +08:00
fix: use shared httpx client to prevent premature closure in SSE streaming
The proxy was creating a temporary httpx.AsyncClient within an async context manager. When returning StreamingResponse for SSE endpoints, the client was being closed before the streaming generator could use it, causing "client has been closed" errors. This change introduces a shared httpx.AsyncClient that persists for the application lifecycle, properly cleaned up during shutdown. This also improves performance by reusing TCP connections across requests. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,8 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
logger.info(f"Proxying to LangGraph server at {config.langgraph_url}")
|
||||
yield
|
||||
logger.info("Shutting down API Gateway")
|
||||
# Close the shared HTTP client
|
||||
await proxy.close_http_client()
|
||||
|
||||
|
||||
def create_app() -> FastAPI:
|
||||
|
||||
Reference in New Issue
Block a user