BUG:Resource Leak in WebSocket Handler - Asyncio Task Not Properly Awaited After Cancellation
Is there an existing issue for this?
- [x] I have searched the existing issues
What happened?
๐ Issue Overview
The WebSocket endpoint in Backend/app/routes/chat.py has a resource leak vulnerability where asyncio tasks are cancelled but not properly awaited, preventing cleanup code from executing and potentially leaving Redis pubsub connections open.
In the WebSocket handler's exception blocks, when a WebSocketDisconnect or general Exception occurs, the code cancels the listener_task but does not await it:
except WebSocketDisconnect:
listener_task.cancel()
await chat_service.disconnect(user_id, redis, db)
except Exception as e:
listener_task.cancel()
await chat_service.disconnect(user_id, redis, db)
Record
- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue
๐ CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
- [ ] Create Plan
๐งช Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
๐ฌ Have feedback or questions? Drop into our discord!
hii please assign me this issue
@ishitaajain22-tech thank you for your interest but I already made a PR for this issue.
Hi! I'd love to work on this issue for GSoC. Could you assign it to me? I can start right away.