Conversation
…tream timeouts, explicit connection cleanup, and documenting production deployment safety.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe SSE notification streaming view now enforces a configurable maximum stream lifetime. A ChangesSSE Stream Deadline and Resource Management
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Pull request overview
This PR updates the notifications Server-Sent Events (SSE) endpoint to better manage long-lived streaming connections under ASGI, aiming to prevent worker-thread and database/redis connection exhaustion while keeping client behavior transparent (EventSource reconnects automatically).
Changes:
- Add a bounded SSE stream lifetime (
MAX_STREAM_SECONDS) so streams self-terminate and reconnect periodically. - Improve redis resource cleanup by closing both the pubsub and the underlying redis client/pool for owned connections.
- Add test coverage to ensure the stream self-terminates once the configured deadline elapses.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| backend/common/views/notification_views.py | Adds stream lifetime cap and strengthens DB/redis cleanup logic for SSE streaming. |
| backend/common/tests/test_notification_sse.py | Adds a regression test to verify the stream terminates at the configured deadline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from django.db import connection | ||
|
|
||
| try: | ||
| notif = Notification.objects.filter( | ||
| pk=notif_id, recipient_id=recipient_id | ||
| ).first() | ||
| if notif is None: | ||
| return None | ||
| return NotificationSerializer(notif).data |
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests