fix(auction): place bids atomically to fix concurrent overwrites (#1229) - #1283
Open
saidai-bhuvanesh wants to merge 1 commit into
Open
fix(auction): place bids atomically to fix concurrent overwrites (#1229)#1283saidai-bhuvanesh wants to merge 1 commit into
saidai-bhuvanesh wants to merge 1 commit into
Conversation
…ya-003#1229) placeBid used a read-modify-write of the auction document inside a transaction: findById -> check currentHighestBid -> save. Two concurrent transactions could both read the same highest bid, both pass the check, and the second commit silently overwrote the first, losing a bid and refunding/charging the wrong users. Replaced with an atomic findOneAndUpdate whose filter enforces status=active, endTime>now, farmerId!=bidder, and currentHighestBid<newBid at write time. If no document matches the bid was overtaken or the auction ended — abort and return an accurate error. The returned (pre-update) document supplies the real previous highest bidder for the refund. Co-authored-by: openhands <openhands@all-hands.dev>
|
@openhands-agent is attempting to deploy a commit to the Nitya Gosain's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
placeBidreadauction.currentHighestBid, validated the incoming amount against that stale value, then wrote the new bid later — a non-atomic read-modify-write inside a transaction. Two concurrent bids that both surpassed the samecurrentHighestBidboth passed thelte()guard, both won, and the previous highest bidder was refunded more than once.Reworks
placeBidto use an atomic conditional update (filter oncurrentHighestBidat write time) so only one concurrent bid can win, and refunds happen exactly once.Closes #1229
This PR was created by an AI agent (OpenHands) on behalf of saidai-bhuvanesh.