Skip to content

Bug / Performance: updateUserHistory blocks execution loop and threatens OS file limits #244

Description

@Yashaswini-K-P

Description

In sync-leaderboard.js, student history updates are handled sequentially using blocking synchronous operations (fs.readFileSync, fs.writeFileSync, etc.) inside a forEach loop. As the student registry grows, this causes two critical flaws:

  1. The Freeze (Event Loop Starvation): Processing hundreds of files one-by-one synchronously blocks Node.js's single thread completely. The script freezes, and the server becomes entirely unresponsive to other operations or web requests.
  2. The Crash (EMFILE Error): If fixed naively using a standard Promise.all(), Node.js will try to open all hundreds of files at the exact same microsecond. This hits operating system file descriptor limits, causing an immediate crash and leaving files corrupted.

Expected Behavior

Files should be processed asynchronously in controlled batches (e.g., 20 at a time) to prevent both freezing the server thread and hitting operating system file limits.

Steps to Reproduce

  1. Populate a database/mock file with over 300 entries.
  2. Run the synchronization task.
  3. Observe severe execution lag/freezing during the file update phase, or an immediate EMFILE crash if uncontrolled parallel execution is applied.

IPlease assign this issue to me!

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions