Skip to content

Fix: Memory Leak in WebSocket Consumers Under High Traffic #45

Description

@Techhackontime999

Description

Under high traffic scenarios (100+ concurrent users), Redis connection pool exhaustion occurs, causing WebSocket connection failures and memory leaks.

Steps to Reproduce

  1. Load test with 100+ concurrent WebSocket connections
  2. Monitor Redis connection count
  3. Notice connections increasing without being released
  4. After ~30 minutes, new connections fail with "Connection pool exhausted"

Expected Behavior

Redis connections should be properly pooled and released. Consumer instances should not hold references after disconnection.

Root Cause

WebSocket consumers don't properly clean up Redis channel layer connections on disconnect. The disconnect() method doesn't always execute, and connection pool settings are too low.

Files to Fix

  • linkup/messaging/consumers.py - Ensure proper cleanup in disconnect() with try/finally
  • linkup/messaging/connection_recovery_manager.py - Fix connection pool reuse
  • linkup/professional_network/settings/base.py - Increase CHANNEL_LAYERS connection pool size
  • Add connection pool monitoring

Acceptance Criteria

  • Redis connections are released on WebSocket disconnect
  • Connection pool size is configurable
  • Memory usage stays stable under load
  • 100+ concurrent connections work without failures

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    advancedAdvanced levelbackendBackend/API workbugSomething isn't workingreal-timeWebSocket/real-time features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions