Fix memory leak in /ai/analyze_stream SSE endpoint (#3949) - #3958
Fix memory leak in /ai/analyze_stream SSE endpoint (#3949)#3958singhanurag0317-bit wants to merge 1 commit into
Conversation
- Add request.is_disconnected() checks at each yield point to detect client disconnects early and stop streaming - Wrap blocking Gemini API calls (analyze_image, get_summary) in asyncio.to_thread + asyncio.wait_for with 30s timeout - Add try/finally/except(CancelledError) cleanup in event_generator - Add Request parameter to endpoint handler Closes riteshbonthalakoti#3949
|
Warning Review limit reached
Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Changes
equest: Request\ parameter to \�nalyze_stream\ endpoint to detect client disconnects
Problem
When clients disconnect mid-stream (page close, network drop), the SSE handler continued running expensive Gemini API calls in the background with no timeout, causing memory leaks and wasted compute.
Solution
Three-layer fix: (1) check disconnect at each step, (2) timeout Gemini calls at 30s, (3) clean up generator on cancellation.
Closes #3949