InPactAI icon indicating copy to clipboard operation
InPactAI copied to clipboard

BUG:Resource Leak in WebSocket Handler - Asyncio Task Not Properly Awaited After Cancellation

Open yugalkaushik opened this issue 11 months ago โ€ข 4 comments

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

yugalkaushik avatar Dec 26 '25 16:12 yugalkaushik

๐Ÿ“ CodeRabbit Plan Mode

Generate an implementation plan and prompts that you can use with your favorite coding agent.

  • [ ] Create Plan
Examples

๐Ÿงช 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!

coderabbitai[bot] avatar Dec 26 '25 16:12 coderabbitai[bot]

hii please assign me this issue

ishitaajain22-tech avatar Feb 05 '26 04:02 ishitaajain22-tech

@ishitaajain22-tech thank you for your interest but I already made a PR for this issue.

yugalkaushik avatar Feb 05 '26 13:02 yugalkaushik

Hi! I'd love to work on this issue for GSoC. Could you assign it to me? I can start right away.

alphacoder-hash avatar Mar 30 '26 05:03 alphacoder-hash