-
Notifications
You must be signed in to change notification settings - Fork 806
Description
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:
- Start the server using npm run start:server.
- Introduce artificial latency (e.g., >150ms) in the fetchLobbies function (or the worker endpoint it calls) so it exceeds the 100ms interval.
- Monitor the Master process memory usage (e.g., using top).
- 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.