Skip to content

Memory Leak in Master Process due to Unbounded setInterval Pile-up #2868

@Codimow

Description

@Codimow

The Master server process uses setInterval to invoke fetchLobbies() every 100ms within src/server/Master.ts. If the execution of fetchLobbies() takes longer than 100ms (e.g. due to network latency, large payloads, or event loop lag), setInterval still schedules the next execution immediately. This results in a "pile-up" of concurrent unresolved Promises and open network sockets. This accumulation leads to excessive memory consumption and eventual process failure.

To Reproduce Steps to reproduce the behavior:

  1. Start the server using npm run start:server.
  2. Introduce artificial latency (e.g., >150ms) in the fetchLobbies function (or the worker endpoint it calls) so it exceeds the 100ms interval.
  3. Monitor the Master process memory usage (e.g., using top).
  4. See error: Memory usage grows continuously as requests stack up, eventually reaching system limits (observed 30GB+).

Expected behavior: The server should wait for the previous fetchLobbies operation to complete (whether it succeeds or fails) before scheduling the next check. This ensures a constant number of concurrent operations regardless of latency.

Desktop (please complete the following information):

OS: Arch Linux
Browser: Firefox
Version: Node.js Server Environment

Additional context

Location:
src/server/Master.ts
Impact: Caused production server to consume 30GB RAM and crash.
Fix: The issue can be resolved by replacing setInterval with a recursive setTimeout pattern in the
Master.ts loop.

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