Skip to content

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

@yugalkaushik

Description

@yugalkaushik

Is there an existing issue for this?

  • 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

  • I agree to follow this project's Code of Conduct
  • I want to work on this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions