fix(bounties): replace read-then-save in expireOverdue with atomic status update guard (#460) - #481
Open
PINYOPATTANAWASANPORN wants to merge 2 commits into
Conversation
…atus update guard (MergeFi#460) Ensure concurrent status transitions (e.g. IN_REVIEW / MERGED / PAID) are not overwritten to EXPIRED by using conditional update on valid status states.
…atus update guard (MergeFi#460) Ensure concurrent status transitions (e.g. IN_REVIEW / MERGED / PAID) are not overwritten to EXPIRED by using conditional update on valid status states.
|
@PINYOPATTANAWASANPORN is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Fixed a concurrency race condition in
BountiesService.expireOverdue()by replacing unconditionalsave()iterations with an atomic conditional status update guard (#460).Root Cause / Technical Context
expireOverdue()previously fetched overdue bounties in OPEN, FUNDED, or CLAIMED status and then calledbountyRepo.save(bounty)on each item.IN_REVIEW,MERGED, orPAIDbetweengetMany()andsave(),save()overwrote the database row withEXPIRED, destroying the concurrent state transition without status re-checking.bountyRepo.save(bounty)withbountyRepo.update({ id, status: In([OPEN, FUNDED, CLAIMED]) }, { status: EXPIRED }).bounties.service.spec.tsvalidating atomic update execution and return counts.Verification & Testing
Ran
npm test -- src/bounties/bounties.service.spec.ts:PASS src/bounties/bounties.service.spec.ts BountiesService √ creates a bounty in OPEN status (12 ms) √ funding an OPEN bounty locks escrow and moves it to FUNDED (3 ms) √ threads the linked GitHub issue id and deadline into escrow.fund (#158) (2 ms) √ rejects funding a bounty that is already FUNDED (15 ms) √ rejects claiming a bounty that is still OPEN (not yet funded) (2 ms) √ claim moves FUNDED -> CLAIMED and records the contributor (1 ms) √ markMergedAndRelease releases escrow to the contributor and moves to PAID (2 ms) √ markMergedAndRelease batches user lookups for team splits (3 ms) √ refund calls escrowService.refund and moves bounty to REFUNDED (2 ms) √ refund skips escrow refund when no escrow is linked (2 ms) √ expireOverdue flips overdue bounties to EXPIRED via atomic update guard (#460) (2 ms) √ markPrClosedWithoutMerge transitions IN_REVIEW back to CLAIMED (1 ms) √ markPrClosedWithoutMerge rejects bounties not in IN_REVIEW (2 ms) √ lists bounties with repository and language filters (2 ms) Test Suites: 1 passed, 1 total Tests: 14 passed, 14 total Snapshots: 0 total Time: 1.65 s