fix(backend): prevent concurrent LeetCode profile verification race conditions (#416)#429
fix(backend): prevent concurrent LeetCode profile verification race conditions (#416)#429itssagarK wants to merge 4 commits into
Conversation
…erification (fixes Ixotic27#416)
|
@itssagarK is attempting to deploy a commit to the ixotic27-8245's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @Ixotic27, This PR fixes the TOCTOU race condition reported in #416. The solution introduces atomic claim logic at the database layer, ensuring that only one user can successfully claim a LeetCode profile even when multiple verification requests occur simultaneously. The existing verification workflow remains unchanged while preventing ownership conflicts and improving profile integrity. Thank you for reviewing. |
|
🚨 Hey @itssagarK, the CI Pipeline is failing on this PR and it has been marked as 🔍 What failed:
📋 Error Details (first 2):
Please fix the issues before this can be reviewed. Here's how: 1. Run checks locally before pushing: npm run lint # Run ESLint
npm run build # Verify production build passes2. Auto-fix common issues: npm run lint -- --fix # Auto-fix lint errors where possible3. Check the full failure log here: Once you push a fix and the CI passes, the |
What does this PR do?
This PR fixes a Time-Of-Check to Time-Of-Use (TOCTOU) race condition in the LeetCode profile verification flow.
Previously, the verification endpoint checked whether a LeetCode profile was available before assigning it to a user. Under concurrent requests, multiple users could pass the availability check and attempt to claim the same profile simultaneously, leading to inconsistent ownership.
This PR introduces an atomic claim mechanism to ensure that only one user can successfully claim a profile.
Changes Made
Atomic Profile Claiming
.is("claimed_by", null)during updates.Safe Profile Creation
409 Conflictif another request claims the profile first.Improved Error Handling
Reduced Race Window
Why this matters
Before this fix
After this fix
Testing
Verified:
Related Issue
Fixes #416
Checklist
npm run lintpasses