Skip to content

fix: resolve timeframe data leak and unawaited writes#321

Merged
jagdish-15 merged 3 commits into
codepvg:mainfrom
Yashaswini-K-P:feat/asyn-io
Jul 15, 2026
Merged

fix: resolve timeframe data leak and unawaited writes#321
jagdish-15 merged 3 commits into
codepvg:mainfrom
Yashaswini-K-P:feat/asyn-io

Conversation

@Yashaswini-K-P

Copy link
Copy Markdown
Contributor

Description

This PR refactors the student history file update system inside sync-leaderboard.js to eliminate Event Loop starvation and prevent operating system resource exhaustion.

Previously, user files were processed sequentially using blocking, synchronous operations (like fs.readFileSync and fs.writeFileSync) inside a heavy loop. As the user registry grew, this completely blocked the Node.js single thread (The Freeze). Transitioning these operations to uncontrolled parallel execution (e.g., a naive Promise.all()) would attempt to open hundreds of files simultaneously, immediately crashing the process with an EMFILE error due to operating system file descriptor limits (The Crash).

This change introduces controlled, asynchronous concurrency limits (chunking) paired with non-blocking Promise-based file system APIs to achieve high performance without compromising server responsiveness or system limits.

Linked Issue

Fixes #244

Changes Made

  • Asynchronous Chunking (DISK_CONCURRENCY_LIMIT): Replaced synchronous file access with asynchronous operations executed in bounded concurrent batches of 20 at a time.
  • Non-blocking Disk I/O: Migrated from synchronous fs methods to fsPromises and atomicWrite inside the user-data synchronization loop, freeing up the Node.js Event Loop to handle concurrent tasks.
  • EMFILE Crash Prevention: Capped concurrent active file handles to safely remain far below system-level open file descriptor limits.

Type of Change

  • Bug fix
  • New feature
  • UI/Visual update
  • Documentation update
  • Refactor

Testing

  • Tested locally
  • Tested on mobile viewport (if applicable)
  • No console errors introduced

Checklist

  • My code follows the project's coding style
  • I have formatted my code locally by running npx prettier --write . before submitting
  • I am submitting my PR from a dedicated feature/* branch, not the main branch
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have updated documentation if required
  • I have linked the relevant issue

Screenshots / Screen Recording

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for submitting a pull request.

Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully.

Formatting and Branching

  • Please confirm you have formatted your code locally using npx prettier --write . before requesting a review.
  • Ensure this PR is made from a feature/* branch and not main.

Note: This project is currently maintained by a solo maintainer, so reviews and responses may sometimes take a little time. Thanks for your patience.

@jagdish-15

Copy link
Copy Markdown
Collaborator

/format

@github-actions

Copy link
Copy Markdown
Contributor

All done! 💅 I've run Prettier and pushed the formatting fixes to this PR.

Just a heads up: Since this commit was pushed by a bot, GitHub won't automatically re-run your CI checks. To trigger them, you can either:

  • Push an empty commit (git commit --allow-empty -m "Trigger builds" and push)
  • Close and immediately reopen this Pull Request.

@jagdish-15 jagdish-15 added type:bug Something isn't working level:advanced Indicates the difficulty gssoc:approved type:performance labels Jul 15, 2026
@jagdish-15 jagdish-15 merged commit d25ae33 into codepvg:main Jul 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved level:advanced Indicates the difficulty type:bug Something isn't working type:performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants