Skip to content

[API] Missing NestJS lifecycle cleanup — intervals, recursive timeouts, stale WS refs #375

@Flegma

Description

@Flegma

Summary

Several services create intervals, timeouts, and track connections but never clean them up on module shutdown.

Findings

  • RedisManagerService — setInterval health checks stored in map but no onApplicationShutdown hook to clear them.
  • MatchAssistantService — setTimeout calls assignServer recursively with no max depth or cleanup reference.
  • SocketsGateway — has handleConnection but no handleDisconnect, leaving stale client references.

Impact

Memory usage grows over time. After extended uptime, services may experience degraded performance or OOM.

Suggested Fix

  • Add OnApplicationShutdown or OnModuleDestroy lifecycle hooks to clear intervals/timeouts.
  • Add handleDisconnect to SocketsGateway.
  • Cap recursive setTimeout depth and store reference for cleanup.

Related Issues (Memory Leak Pattern)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-highStability & reliabilityaudit-2026-03From March 2026 codebase auditmemory-leakMemory or subscription leakservice:api5stackgg/api service

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions