Describe the bug
async def stream_claude_response(...) -> Completion:
client = AsyncAnthropic(api_key=api_key)
# ... streaming code ...
await client.close() # Only reached on success!
Problem: If an exception occurs during streaming, client.close() is never called. No try/finally block exists. Both stream_claude_response and stream_claude_response_native have this issue.
Impact: Connection pool exhaustion in long-running sessions. Memory leak of HTTP connections. Eventually backend stops accepting new requests.
To Reproduce
Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
Screenshots of backend AND frontend terminal logs
If applicable, add screenshots to help explain your problem.
I'd like to put the PR if you want to proceed this one.
Describe the bug
Problem: If an exception occurs during streaming,
client.close()is never called. No try/finally block exists. Bothstream_claude_responseandstream_claude_response_nativehave this issue.Impact: Connection pool exhaustion in long-running sessions. Memory leak of HTTP connections. Eventually backend stops accepting new requests.
To Reproduce
Steps to reproduce the behavior:
Screenshots of backend AND frontend terminal logs
If applicable, add screenshots to help explain your problem.
I'd like to put the PR if you want to proceed this one.