Skip to content

fix: resolve race condition in reply voting system#335

Merged
knoxiboy merged 2 commits into
knoxiboy:mainfrom
ash1shkumar:fix/reply-vote-race-condition
May 26, 2026
Merged

fix: resolve race condition in reply voting system#335
knoxiboy merged 2 commits into
knoxiboy:mainfrom
ash1shkumar:fix/reply-vote-race-condition

Conversation

@ash1shkumar
Copy link
Copy Markdown
Contributor

Description

Implemented a transaction-safe reply voting system to prevent race conditions and vote count desynchronization during concurrent requests.

Changes Made

  • wrapped reply voting operations inside db.transaction()
  • converted vote updates into atomic DB operations
  • prevented partial updates during concurrent voting
  • added protection against negative vote counts using GREATEST()
  • improved backend consistency for rapid/multi-tab voting scenarios
  • added graceful duplicate vote error handling

Related Issue

Closes #329

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update (README, guides, comments)
  • Style / UI change (no logic change)
  • Code refactor (no behavior change)
  • Test addition or update
  • Breaking change (fix or feature that would cause existing functionality to change)

How Has This Been Tested?

  • Tested locally with npm run dev
  • Verified on mobile viewport (375px)
  • Verified on desktop viewport (1440px)

Manual Testing Performed

  • rapid repeated vote/unvote actions
  • multi-tab concurrent voting simulation
  • verified prevention of negative vote counts
  • verified vote consistency during concurrent operations

Checklist

  • I have tested my changes locally (npm run dev)
  • My code follows the existing code style (TypeScript, Tailwind, no any types)
  • I have not introduced unrelated changes (each PR should address one issue)
  • I have added comments where necessary
  • My branch is up to date with main
  • I have linked the related issue above
  • Screenshots are included (if this is a UI change)

##Expected Level
Level3/advanced

I am contributing under GSSoC and NSoC

@vercel
Copy link
Copy Markdown

vercel Bot commented May 25, 2026

@ash1shkumar is attempting to deploy a commit to the Karan Mani Tripathi 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot requested a review from knoxiboy May 25, 2026 16:34
@github-actions github-actions Bot added gssoc'26 GSSoC program issue level:beginner Beginner level task type:docs Documentation update type:feature New feature labels May 25, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technical Review

Hi @ash1shkumar! Thank you for your contribution to DoubtDesk.

The code changes look good. Before we can complete the technical review, approve, and merge this pull request, we have one final requirement for all contributors: Please star the DoubtDesk repository.

Once you have starred the repository, please drop a comment here saying "done" (or we will automatically detect it) and we will proceed with approving and merging your PR. Thank you.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there! 🎉 Thank you so much for your first pull request to DoubtDesk!

We really appreciate your contribution. A maintainer will review your code soon. If you are participating in GSSoC, ensure your PR is linked to an open issue. Please make sure you have followed all rules in our Contributing Guidelines. Happy coding!

@ash1shkumar
Copy link
Copy Markdown
Contributor Author

Technical Review

Hi @ash1shkumar! Thank you for your contribution to DoubtDesk.

The code changes look good. Before we can complete the technical review, approve, and merge this pull request, we have one final requirement for all contributors: Please star the DoubtDesk repository.

Once you have starred the repository, please drop a comment here saying "done" (or we will automatically detect it) and we will proceed with approving and merging your PR. Thank you.

done

@ash1shkumar
Copy link
Copy Markdown
Contributor Author

Hi @knoxiboy , could you please review this PR when available?

This fix addresses a backend race condition and transactional consistency issue in the reply voting system by implementing atomic DB transactions and preventing vote count desynchronization during concurrent requests.

Since the issue involves concurrency handling, database integrity, and transaction-safe operations, I believe it would fit better under a level:advanced label instead of level:beginner.

Thank you!

@knoxiboy knoxiboy merged commit 65baea9 into knoxiboy:main May 26, 2026
4 of 5 checks passed
@github-actions github-actions Bot added gssoc:approved Approved for GSSoC mentor:knoxiboy Reviewed by mentor knoxiboy quality:clean Clean code quality and removed size/m review-needed labels May 26, 2026
@ash1shkumar
Copy link
Copy Markdown
Contributor Author

@knoxiboy , This PR fix addresses a backend race condition and transactional consistency issue in the reply voting system by implementing atomic DB transactions and preventing vote count desynchronization during concurrent requests.

Since the issue involves concurrency handling, database integrity, and transaction-safe operations, I believe it would fit better under a level:advanced label instead of level:beginner.

Thank you!

@ash1shkumar ash1shkumar deleted the fix/reply-vote-race-condition branch May 26, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC gssoc'26 GSSoC program issue level:beginner Beginner level task mentor:knoxiboy Reviewed by mentor knoxiboy quality:clean Clean code quality type:docs Documentation update type:feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Race Condition in Reply Voting System Causes Vote Count Desynchronization

2 participants