Skip to content

process.exit(1) on Any Single User's API Failure Destroys Entire Sync Cycle #61

@rishab11250

Description

@rishab11250

Severity

Critical — Makes the entire sync pipeline unreliable

Location

scripts/sync-leaderboard.js:14-15

Description

fetchData() terminates the entire Node process if any single user's API call fails:

async function fetchData(url) {
  try {
    const res = await axios.get(url);
    return {
      easySolved: res.data.easySolved || 0,
      mediumSolved: res.data.mediumSolved || 0,
      hardSolved: res.data.hardSolved || 0
    };
  } catch (err) {
    console.error("API failed to respond: ", err.message);
    process.exit(1);   // kills everything
  }
}

With 10+ users hitting a third-party API, transient failures are guaranteed. When
one user fails:

  • All previously fetched data (other users) is lost
  • CI iteration running at 300s intervals is wasted
  • With continue-on-error: true, the failure is invisible
  • No Axios timeout (default: 0 = infinite) means a hang kills the entire 6-hour run

Why It Matters

  • The sync script generates all leaderboard data — it's the most critical function
  • Third-party APIs are inherently unreliable
  • A single rate-limited user means zero data for everyone that cycle
  • No partial-results fallback

Fix

async function fetchData(url) {
  try {
    const res = await axios.get(url, { timeout: 15000 });
    return {
      easySolved: res.data.easySolved || 0,
      mediumSolved: res.data.mediumSolved || 0,
      hardSolved: res.data.hardSolved || 0
    };
  } catch (err) {
    console.error(`API failed for ${url}: ${err.message}`);
    return null;  // signal failure without killing process
  }
}

// In the loop:
if (data === null) {
  console.log(`Skipping ${user.name} due to API error`);
  continue;
}

Metadata

Metadata

Assignees

Labels

BackendTask mainly involving backendlevel:intermediateIndicates the difficultytype:bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions